Skip to content

Commit 621b2eb

Browse files
committed
test: cover filter discovery skipping the default Config/Filters.php files
1 parent 15586a0 commit 621b2eb

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎tests/system/Filters/FiltersTest.php‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CodeIgniter\Filters;
1515

16+
use CodeIgniter\Autoloader\FileLocator;
1617
use CodeIgniter\Config\Services;
1718
use CodeIgniter\Filters\Exceptions\FilterException;
1819
use CodeIgniter\Filters\fixtures\GoogleCurious;
@@ -488,6 +489,52 @@ public function testAllCustomFiltersAreDiscoveredInConstructor(): void
488489
$this->assertContains('test-customfilter', array_keys($configFilters->aliases));
489490
}
490491

492+
public function testDiscoveryDoesNotTokenizeTheDefaultFiltersConfigs(): void
493+
{
494+
service('superglobals')->setServer('REQUEST_METHOD', 'GET');
495+
496+
$locator = new class (service('autoloader')) extends FileLocator {
497+
/**
498+
* @var list<string>
499+
*/
500+
public array $tokenized = [];
501+
502+
public function getClassname(string $file): string
503+
{
504+
$this->tokenized[] = $file;
505+
506+
return parent::getClassname($file);
507+
}
508+
};
509+
Services::injectMock('locator', $locator);
510+
511+
$appConfig = APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Filters.php';
512+
$systemConfig = SYSTEMPATH . 'Config' . DIRECTORY_SEPARATOR . 'Filters.php';
513+
$testConfig = realpath(TESTPATH . '_support/Config/Filters.php');
514+
515+
// Discovery does find them all, so the checks below are not vacuous.
516+
$found = $locator->search('Config/Filters.php');
517+
$this->assertContains($appConfig, $found);
518+
$this->assertContains($systemConfig, $found);
519+
$this->assertContains($testConfig, $found);
520+
521+
$config = [
522+
'aliases' => [],
523+
'globals' => [],
524+
];
525+
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
526+
$filters = $this->createFilters($filtersConfig);
527+
528+
$this->assertNotContains($appConfig, $locator->tokenized);
529+
$this->assertNotContains($systemConfig, $locator->tokenized);
530+
531+
// Any other file is still checked and included.
532+
$this->assertContains($testConfig, $locator->tokenized);
533+
534+
$configFilters = $this->getPrivateProperty($filters, 'config');
535+
$this->assertContains('test-customfilter', array_keys($configFilters->aliases));
536+
}
537+
491538
public function testRunThrowsWithInvalidClassType(): void
492539
{
493540
service('superglobals')->setServer('REQUEST_METHOD', 'GET');

0 commit comments

Comments
 (0)