-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
bugVerified issues on the current code behavior or pull requests that will fix themVerified issues on the current code behavior or pull requests that will fix them
Description
Description
When I test a method that has a filter defined in the route config file, it works.
But when I immediately try another method that has no filter defined in the route configuration file, the filter of the previously tested method is executed.
Here an example:
This is my controller:
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use Config\Services;
class Filter extends BaseController
{
public function methodOne()
{
}
public function methodTwo()
{
return Services::response()->setBody('I am Method Two');
}
}
My Filter:
<?php
namespace App\Filters;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Services;
class Filter implements FilterInterface
{
/**
* {@inheritdoc}
*/
public function before(RequestInterface $request, $arguments = null)
{
return Services::response()->setBody('I am Filter');
}
/**
* {@inheritdoc}
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
//
}
}
And I definied two routes in App\Config\Routes.php
$routes->get('method_one','Filter::methodOne', ['filter' => 'Filter']);
$routes->get('method_two','Filter::methodTwo');
And finally my test:
<?php
namespace App;
use CodeIgniter\Test\FeatureTestCase;
class FilterTest extends FeatureTestCase
{
public function setUp(): void
{
parent::setUp();
}
public function tearDown(): void
{
parent::tearDown();
}
public function testMethodOne(): void
{
$result = $this->get('method_one');
$result->assertSee('I am Filter');
}
public function testMethodTwo(): void
{
$result = $this->get('method_two');
$result->assertSee('I am Method Two');
}
}
When I run my test I get the following
PD: Another bug? When filter return an response, phpunit show me the response body in terminal. It is ok?
CodeIgniter Version
CodeIgniter 4.0.4 - branch develop
Context
- OS: [Linux]
- PHP version [7.4]
Metadata
Metadata
Assignees
Labels
bugVerified issues on the current code behavior or pull requests that will fix themVerified issues on the current code behavior or pull requests that will fix them
