Skip to content

Commit f563b27

Browse files
committed
Improve tests and formatting
1 parent a875e19 commit f563b27

File tree

5 files changed

+20
-43
lines changed

5 files changed

+20
-43
lines changed

src/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ public function __invoke($component, $props)
88
{
99
return Inertia::render($component, $props);
1010
}
11-
}
11+
}

src/ServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class ServiceProvider extends BaseServiceProvider
1010
{
1111
/**
1212
* Perform post-registration booting of services.
13-
*
14-
* @return void
1513
*/
1614
public function boot()
1715
{

tests/ControllerTest.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,24 @@
22

33
namespace Inertia\Tests;
44

5-
use Illuminate\Http\Request;
5+
use Inertia\Response;
66
use Inertia\Controller;
7+
use Illuminate\Http\Request;
78

89
class ControllerTest extends TestCase
910
{
10-
public function test_it_returns_an_inertia_response()
11+
public function test_controller_returns_an_inertia_response()
1112
{
12-
$request = new Request();
13-
$request->headers->set('X-Inertia-Partial-Component', 'Component');
14-
$controller = new Controller();
15-
16-
$response = $controller('Component', ['prop1' => true, 'prop2' => false])->toResponse($request);
17-
13+
$response = (new Controller())('User/Edit', ['user' => ['name' => 'Jonathan']]);
1814

19-
$this->assertEquals('app', $response->name());
15+
$this->assertInstanceOf(Response::class, $response);
2016
$this->assertEquals([
2117
'page' => [
22-
'component' => 'Component',
23-
'props' => [
24-
'prop1' => true,
25-
'prop2' => false,
26-
],
18+
'component' => 'User/Edit',
19+
'props' => ['user' => ['name' => 'Jonathan']],
2720
'url' => '',
2821
'version' => null,
29-
]
30-
], $response->getData());
22+
],
23+
], $response->toResponse(new Request())->getData());
3124
}
32-
}
25+
}

tests/HelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function test_the_helper_function_returns_an_instance_of_the_response_fac
1515

1616
public function test_the_helper_function_returns_a_response_instance()
1717
{
18-
$this->assertInstanceOf(Response::class, inertia('User/Edit', ['user' => ['name' => 'George']]));
18+
$this->assertInstanceOf(Response::class, inertia('User/Edit', ['user' => ['name' => 'Jonathan']]));
1919
}
2020

2121
public function test_the_instance_is_the_same_as_the_facade_instance()

tests/RouterTest.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,20 @@
22

33
namespace Inertia\Tests;
44

5-
use Illuminate\Routing\RouteCollection;
65
use Illuminate\Support\Facades\Route;
76

87
class RouterTest extends TestCase
98
{
10-
public function test_configuring_route_via_macro()
9+
public function test_inertia_route_macro()
1110
{
12-
/** @var \Illuminate\Routing\Route $route */
13-
$route = Route::inertia('/', 'Component', ['prop1' => true, 'prop2' => false]);
14-
15-
/** @var RouteCollection $collection */
16-
$collection = Route::getRoutes();
17-
18-
$this->assertNotEmpty($collection->getRoutes());
19-
$this->assertEquals($route, $collection->getRoutes()[0]);
11+
$route = Route::inertia('/', 'User/Edit', ['user' => ['name' => 'Jonathan']]);
12+
$routes = Route::getRoutes();
2013

14+
$this->assertNotEmpty($routes->getRoutes());
15+
$this->assertEquals($route, $routes->getRoutes()[0]);
2116
$this->assertEquals(['GET', 'HEAD'], $route->methods);
22-
2317
$this->assertEquals('/', $route->uri);
24-
25-
$this->assertEquals([
26-
'uses' => '\Inertia\Controller@__invoke',
27-
'controller' => '\Inertia\Controller',
28-
], $route->action);
29-
30-
$this->assertEquals([
31-
'component' => 'Component',
32-
'props' => ['prop1' => true, 'prop2' => false],
33-
], $route->defaults);
18+
$this->assertEquals(['uses' => '\Inertia\Controller@__invoke', 'controller' => '\Inertia\Controller'], $route->action);
19+
$this->assertEquals(['component' => 'User/Edit', 'props' => ['user' => ['name' => 'Jonathan']]], $route->defaults);
3420
}
35-
}
21+
}

0 commit comments

Comments
 (0)