|
11 | 11 |
|
12 | 12 | namespace CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved; |
13 | 13 |
|
| 14 | +use CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\Controllers\Home; |
14 | 15 | use CodeIgniter\Test\CIUnitTestCase; |
15 | 16 | use Tests\Support\Controllers\Newautorouting; |
16 | 17 | use Tests\Support\Controllers\Remap; |
|
22 | 23 | */ |
23 | 24 | final class ControllerMethodReaderTest extends CIUnitTestCase |
24 | 25 | { |
25 | | - private function createControllerMethodReader(): ControllerMethodReader |
26 | | - { |
| 26 | + private function createControllerMethodReader( |
| 27 | + string $namespace = 'Tests\Support\Controllers' |
| 28 | + ): ControllerMethodReader { |
27 | 29 | $methods = [ |
28 | 30 | 'get', |
29 | 31 | 'post', |
30 | 32 | ]; |
31 | | - $namespace = 'Tests\Support\Controllers'; |
32 | 33 |
|
33 | 34 | return new ControllerMethodReader($namespace, $methods); |
34 | 35 | } |
@@ -63,6 +64,41 @@ public function testRead() |
63 | 64 | $this->assertSame($expected, $routes); |
64 | 65 | } |
65 | 66 |
|
| 67 | + public function testReadDefaultController() |
| 68 | + { |
| 69 | + $reader = $this->createControllerMethodReader( |
| 70 | + 'CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\Controllers' |
| 71 | + ); |
| 72 | + |
| 73 | + $routes = $reader->read(Home::class); |
| 74 | + |
| 75 | + $expected = [ |
| 76 | + 0 => [ |
| 77 | + 'method' => 'get', |
| 78 | + 'route' => '/', |
| 79 | + 'route_params' => '', |
| 80 | + 'handler' => '\CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\Controllers\Home::getIndex', |
| 81 | + 'params' => [], |
| 82 | + ], |
| 83 | + [ |
| 84 | + 'method' => 'post', |
| 85 | + 'route' => '/', |
| 86 | + 'route_params' => '', |
| 87 | + 'handler' => '\CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\Controllers\Home::postIndex', |
| 88 | + 'params' => [], |
| 89 | + ], |
| 90 | + [ |
| 91 | + 'method' => 'get', |
| 92 | + 'route' => 'x home/foo', |
| 93 | + 'route_params' => '', |
| 94 | + 'handler' => '\CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\Controllers\Home::getFoo', |
| 95 | + 'params' => [], |
| 96 | + ], |
| 97 | + ]; |
| 98 | + |
| 99 | + $this->assertSame($expected, $routes); |
| 100 | + } |
| 101 | + |
66 | 102 | public function testReadControllerWithRemap() |
67 | 103 | { |
68 | 104 | $reader = $this->createControllerMethodReader(); |
|
0 commit comments