Skip to content

Commit d4bcffd

Browse files
committed
test: add test for feature testing and auto routing improved
1 parent 49dabc1 commit d4bcffd

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Test;
13+
14+
use CodeIgniter\Events\Events;
15+
use Config\Feature;
16+
use Config\Services;
17+
18+
/**
19+
* @group Others
20+
*
21+
* @internal
22+
*/
23+
final class FeatureTestAutoRoutingImprovedTest extends CIUnitTestCase
24+
{
25+
use FeatureTestTrait;
26+
27+
public static function setUpBeforeClass(): void
28+
{
29+
parent::setUpBeforeClass();
30+
31+
Events::simulate(true);
32+
33+
self::initializeRouter();
34+
}
35+
36+
public static function tearDownAfterClass(): void
37+
{
38+
parent::tearDownAfterClass();
39+
40+
Events::simulate(false);
41+
42+
Services::reset();
43+
}
44+
45+
private static function initializeRouter(): void
46+
{
47+
$routes = Services::routes();
48+
$routes->resetRoutes();
49+
$routes->loadRoutes();
50+
51+
$routes->setAutoRoute(true);
52+
config(Feature::class)->autoRoutesImproved = true;
53+
54+
$namespace = 'Tests\Support\Controllers';
55+
$routes->setDefaultNamespace($namespace);
56+
57+
$router = Services::router($routes);
58+
59+
Services::injectMock('router', $router);
60+
}
61+
62+
public function testCallGet()
63+
{
64+
$response = $this->get('newautorouting');
65+
66+
$response->assertSee('Hello');
67+
}
68+
69+
public function testCallPost()
70+
{
71+
$response = $this->post('newautorouting/save/1/a/b');
72+
73+
$response->assertSee('Saved');
74+
}
75+
}

0 commit comments

Comments
 (0)