From f563b279a62a6234546d4954ba756ebc432c55f5 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Mon, 26 Aug 2019 13:04:43 -0400 Subject: [PATCH] Improve tests and formatting --- src/Controller.php | 2 +- src/ServiceProvider.php | 2 -- tests/ControllerTest.php | 27 ++++++++++----------------- tests/HelperTest.php | 2 +- tests/RouterTest.php | 30 ++++++++---------------------- 5 files changed, 20 insertions(+), 43 deletions(-) diff --git a/src/Controller.php b/src/Controller.php index 65dceaed..1c41d67a 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -8,4 +8,4 @@ public function __invoke($component, $props) { return Inertia::render($component, $props); } -} \ No newline at end of file +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 942bb89e..3c95afb2 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -10,8 +10,6 @@ class ServiceProvider extends BaseServiceProvider { /** * Perform post-registration booting of services. - * - * @return void */ public function boot() { diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index d7a302eb..4dc03a41 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -2,31 +2,24 @@ namespace Inertia\Tests; -use Illuminate\Http\Request; +use Inertia\Response; use Inertia\Controller; +use Illuminate\Http\Request; class ControllerTest extends TestCase { - public function test_it_returns_an_inertia_response() + public function test_controller_returns_an_inertia_response() { - $request = new Request(); - $request->headers->set('X-Inertia-Partial-Component', 'Component'); - $controller = new Controller(); - - $response = $controller('Component', ['prop1' => true, 'prop2' => false])->toResponse($request); - + $response = (new Controller())('User/Edit', ['user' => ['name' => 'Jonathan']]); - $this->assertEquals('app', $response->name()); + $this->assertInstanceOf(Response::class, $response); $this->assertEquals([ 'page' => [ - 'component' => 'Component', - 'props' => [ - 'prop1' => true, - 'prop2' => false, - ], + 'component' => 'User/Edit', + 'props' => ['user' => ['name' => 'Jonathan']], 'url' => '', 'version' => null, - ] - ], $response->getData()); + ], + ], $response->toResponse(new Request())->getData()); } -} \ No newline at end of file +} diff --git a/tests/HelperTest.php b/tests/HelperTest.php index 6a8fb5d1..ae15cbac 100644 --- a/tests/HelperTest.php +++ b/tests/HelperTest.php @@ -15,7 +15,7 @@ public function test_the_helper_function_returns_an_instance_of_the_response_fac public function test_the_helper_function_returns_a_response_instance() { - $this->assertInstanceOf(Response::class, inertia('User/Edit', ['user' => ['name' => 'George']])); + $this->assertInstanceOf(Response::class, inertia('User/Edit', ['user' => ['name' => 'Jonathan']])); } public function test_the_instance_is_the_same_as_the_facade_instance() diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 85c49236..9c04190d 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -2,34 +2,20 @@ namespace Inertia\Tests; -use Illuminate\Routing\RouteCollection; use Illuminate\Support\Facades\Route; class RouterTest extends TestCase { - public function test_configuring_route_via_macro() + public function test_inertia_route_macro() { - /** @var \Illuminate\Routing\Route $route */ - $route = Route::inertia('/', 'Component', ['prop1' => true, 'prop2' => false]); - - /** @var RouteCollection $collection */ - $collection = Route::getRoutes(); - - $this->assertNotEmpty($collection->getRoutes()); - $this->assertEquals($route, $collection->getRoutes()[0]); + $route = Route::inertia('/', 'User/Edit', ['user' => ['name' => 'Jonathan']]); + $routes = Route::getRoutes(); + $this->assertNotEmpty($routes->getRoutes()); + $this->assertEquals($route, $routes->getRoutes()[0]); $this->assertEquals(['GET', 'HEAD'], $route->methods); - $this->assertEquals('/', $route->uri); - - $this->assertEquals([ - 'uses' => '\Inertia\Controller@__invoke', - 'controller' => '\Inertia\Controller', - ], $route->action); - - $this->assertEquals([ - 'component' => 'Component', - 'props' => ['prop1' => true, 'prop2' => false], - ], $route->defaults); + $this->assertEquals(['uses' => '\Inertia\Controller@__invoke', 'controller' => '\Inertia\Controller'], $route->action); + $this->assertEquals(['component' => 'User/Edit', 'props' => ['user' => ['name' => 'Jonathan']]], $route->defaults); } -} \ No newline at end of file +}