|
4 | 4 | use Spatie\RouteAttributes\Tests\TestClasses\Controllers\DomainTestController; |
5 | 5 |
|
6 | 6 | it('can apply a domain on the url of every method', function () { |
7 | | - $this->routeRegistrar->registerClass(DomainTestController::class); |
| 7 | + $this->routeRegistrar->registerClass(DomainTestController::class); |
8 | 8 |
|
9 | | - $this |
10 | | - ->expectRegisteredRoutesCount(2) |
11 | | - ->expectRouteRegistered( |
12 | | - DomainTestController::class, |
13 | | - controllerMethod: 'myGetMethod', |
14 | | - uri: 'my-get-method', |
15 | | - domain: 'my-subdomain.localhost' |
16 | | - ) |
17 | | - ->expectRouteRegistered( |
18 | | - DomainTestController::class, |
19 | | - controllerMethod: 'myPostMethod', |
20 | | - httpMethods: 'post', |
21 | | - uri: 'my-post-method', |
22 | | - domain: 'my-subdomain.localhost' |
23 | | - ); |
| 9 | + $this |
| 10 | + ->expectRegisteredRoutesCount(2) |
| 11 | + ->expectRouteRegistered( |
| 12 | + DomainTestController::class, |
| 13 | + controllerMethod: 'myGetMethod', |
| 14 | + uri: 'my-get-method', |
| 15 | + domain: 'my-subdomain.localhost' |
| 16 | + ) |
| 17 | + ->expectRouteRegistered( |
| 18 | + DomainTestController::class, |
| 19 | + controllerMethod: 'myPostMethod', |
| 20 | + httpMethods: 'post', |
| 21 | + uri: 'my-post-method', |
| 22 | + domain: 'my-subdomain.localhost' |
| 23 | + ); |
24 | 24 | }); |
25 | 25 |
|
26 | 26 | it('registers domain files before non domain files', function () { |
27 | | - // Use registerDirectory to test file-level domain ordering |
28 | | - $this->routeRegistrar->registerDirectory($this->getTestPath('TestClasses/Controllers')); |
29 | | - $routes = collect($this->getRouteCollection()->getRoutes()); |
| 27 | + // Use registerDirectory to test file-level domain ordering |
| 28 | + $this->routeRegistrar->registerDirectory($this->getTestPath('TestClasses/Controllers')); |
| 29 | + $routes = collect($this->getRouteCollection()->getRoutes()); |
30 | 30 |
|
31 | | - // Find all domain routes and non-domain routes |
32 | | - $domainRoutes = $routes->filter(fn ($route) => $route->getDomain() !== null); |
33 | | - $nonDomainRoutes = $routes->filter(fn ($route) => $route->getDomain() === null); |
| 31 | + // Find all domain routes and non-domain routes |
| 32 | + $domainRoutes = $routes->filter(fn ($route) => $route->getDomain() !== null); |
| 33 | + $nonDomainRoutes = $routes->filter(fn ($route) => $route->getDomain() === null); |
34 | 34 |
|
35 | | - // Get the last index of domain routes and first index of non-domain routes |
36 | | - $allRoutes = $routes->values(); |
| 35 | + // Get the last index of domain routes and first index of non-domain routes |
| 36 | + $allRoutes = $routes->values(); |
37 | 37 |
|
38 | | - // Find the last domain route index |
39 | | - $lastDomainIndex = null; |
40 | | - foreach ($domainRoutes as $domainRoute) { |
41 | | - $index = $allRoutes->search($domainRoute); |
42 | | - if ($lastDomainIndex === null || $index > $lastDomainIndex) { |
43 | | - $lastDomainIndex = $index; |
44 | | - } |
| 38 | + // Find the last domain route index |
| 39 | + $lastDomainIndex = null; |
| 40 | + foreach ($domainRoutes as $domainRoute) { |
| 41 | + $index = $allRoutes->search($domainRoute); |
| 42 | + if ($lastDomainIndex === null || $index > $lastDomainIndex) { |
| 43 | + $lastDomainIndex = $index; |
45 | 44 | } |
| 45 | + } |
46 | 46 |
|
47 | | - // Find the first non-domain route index |
48 | | - $firstNonDomainIndex = null; |
49 | | - foreach ($nonDomainRoutes as $nonDomainRoute) { |
50 | | - $index = $allRoutes->search($nonDomainRoute); |
51 | | - if ($firstNonDomainIndex === null || $index < $firstNonDomainIndex) { |
52 | | - $firstNonDomainIndex = $index; |
53 | | - } |
| 47 | + // Find the first non-domain route index |
| 48 | + $firstNonDomainIndex = null; |
| 49 | + foreach ($nonDomainRoutes as $nonDomainRoute) { |
| 50 | + $index = $allRoutes->search($nonDomainRoute); |
| 51 | + if ($firstNonDomainIndex === null || $index < $firstNonDomainIndex) { |
| 52 | + $firstNonDomainIndex = $index; |
54 | 53 | } |
| 54 | + } |
55 | 55 |
|
56 | | - // All domain routes should come before all non-domain routes |
57 | | - $this->assertLessThan( |
58 | | - $firstNonDomainIndex, |
59 | | - $lastDomainIndex, |
60 | | - 'All domain routes should be registered before all non-domain routes', |
61 | | - ); |
| 56 | + // All domain routes should come before all non-domain routes |
| 57 | + $this->assertLessThan( |
| 58 | + $firstNonDomainIndex, |
| 59 | + $lastDomainIndex, |
| 60 | + 'All domain routes should be registered before all non-domain routes', |
| 61 | + ); |
62 | 62 | }); |
63 | 63 |
|
64 | 64 | it('registers domain routes before other routes in domain order test controller', function () { |
65 | | - $this->routeRegistrar->registerClass(DomainOrderTestController::class); |
| 65 | + $this->routeRegistrar->registerClass(DomainOrderTestController::class); |
66 | 66 |
|
67 | | - $routes = $this->expectRegisteredRoutesCount(4)->getRouteCollection()->getRoutes(); |
| 67 | + $routes = $this->expectRegisteredRoutesCount(4)->getRouteCollection()->getRoutes(); |
68 | 68 |
|
69 | | - $this->assertNotNull($routes[0]->domain()); |
70 | | - $this->assertNotNull($routes[1]->domain()); |
71 | | - $this->assertNull($routes[2]->domain()); |
72 | | - $this->assertNull($routes[3]->domain()); |
| 69 | + $this->assertNotNull($routes[0]->domain()); |
| 70 | + $this->assertNotNull($routes[1]->domain()); |
| 71 | + $this->assertNull($routes[2]->domain()); |
| 72 | + $this->assertNull($routes[3]->domain()); |
73 | 73 | }); |
0 commit comments