-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for feature testing and auto routing improved
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Test; | ||
|
||
use CodeIgniter\Events\Events; | ||
use Config\Feature; | ||
use Config\Services; | ||
|
||
/** | ||
* @group Others | ||
* | ||
* @internal | ||
*/ | ||
final class FeatureTestAutoRoutingImprovedTest extends CIUnitTestCase | ||
{ | ||
use FeatureTestTrait; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
Events::simulate(true); | ||
|
||
self::initializeRouter(); | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
parent::tearDownAfterClass(); | ||
|
||
Events::simulate(false); | ||
|
||
Services::reset(); | ||
} | ||
|
||
private static function initializeRouter(): void | ||
{ | ||
$routes = Services::routes(); | ||
$routes->resetRoutes(); | ||
$routes->loadRoutes(); | ||
|
||
$routes->setAutoRoute(true); | ||
config(Feature::class)->autoRoutesImproved = true; | ||
|
||
$namespace = 'Tests\Support\Controllers'; | ||
$routes->setDefaultNamespace($namespace); | ||
|
||
$router = Services::router($routes); | ||
|
||
Services::injectMock('router', $router); | ||
} | ||
|
||
public function testCallGet() | ||
{ | ||
$response = $this->get('newautorouting'); | ||
|
||
$response->assertSee('Hello'); | ||
} | ||
|
||
public function testCallPost() | ||
{ | ||
$response = $this->post('newautorouting/save/1/a/b'); | ||
|
||
$response->assertSee('Saved'); | ||
} | ||
} |