Skip to content

Commit

Permalink
test: add test for feature testing and auto routing improved
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jun 6, 2023
1 parent 85bfa44 commit b9747ea
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/system/Test/FeatureTestAutoRoutingImprovedTest.php
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');
}
}

0 comments on commit b9747ea

Please sign in to comment.