Skip to content

Commit f9ecd03

Browse files
committed
test: use dataProvider
1 parent 459ea26 commit f9ecd03

File tree

1 file changed

+36
-68
lines changed

1 file changed

+36
-68
lines changed

tests/system/Filters/FiltersTest.php

Lines changed: 36 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,12 @@ public function testOtherResult(): void
580580
$this->assertSame('This is curious', $response);
581581
}
582582

583-
public function testBeforeExceptString(): void
583+
/**
584+
* @dataProvider provideBeforeExcept
585+
*
586+
* @param array|string $except
587+
*/
588+
public function testBeforeExcept(string $uri, $except, array $expected): void
584589
{
585590
$_SERVER['REQUEST_METHOD'] = 'GET';
586591

@@ -592,7 +597,7 @@ public function testBeforeExceptString(): void
592597
],
593598
'globals' => [
594599
'before' => [
595-
'foo' => ['except' => 'admin/*'],
600+
'foo' => ['except' => $except],
596601
'bar',
597602
],
598603
'after' => [
@@ -603,82 +608,45 @@ public function testBeforeExceptString(): void
603608
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
604609
$filters = $this->createFilters($filtersConfig);
605610

606-
$uri = 'admin/foo/bar';
607-
$expected = [
608-
'before' => [
609-
'bar',
610-
],
611-
'after' => ['baz'],
612-
];
613611
$this->assertSame($expected, $filters->initialize($uri)->getFilters());
614612
}
615613

616-
public function testBeforeExceptInapplicable(): void
614+
public static function provideBeforeExcept(): iterable
617615
{
618-
$_SERVER['REQUEST_METHOD'] = 'GET';
619-
620-
$config = [
621-
'aliases' => [
622-
'foo' => '',
623-
'bar' => '',
624-
'baz' => '',
625-
],
626-
'globals' => [
627-
'before' => [
628-
'foo' => ['except' => 'george/*'],
629-
'bar',
630-
],
631-
'after' => [
632-
'baz',
616+
return [
617+
'string exclude' => [
618+
'admin/foo/bar',
619+
'admin/*',
620+
[
621+
'before' => [
622+
'bar',
623+
],
624+
'after' => ['baz'],
633625
],
634626
],
635-
];
636-
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
637-
$filters = $this->createFilters($filtersConfig);
638-
639-
$uri = 'admin/foo/bar';
640-
$expected = [
641-
'before' => [
642-
'foo',
643-
'bar',
644-
],
645-
'after' => ['baz'],
646-
];
647-
$this->assertSame($expected, $filters->initialize($uri)->getFilters());
648-
}
649-
650-
public function testBeforeExceptEmptyArray(): void
651-
{
652-
$_SERVER['REQUEST_METHOD'] = 'GET';
653-
654-
$config = [
655-
'aliases' => [
656-
'foo' => '',
657-
'bar' => '',
658-
'baz' => '',
659-
],
660-
'globals' => [
661-
'before' => [
662-
'foo' => ['except' => []],
663-
'bar',
664-
],
665-
'after' => [
666-
'baz',
627+
'string not exclude' => [
628+
'admin/foo/bar',
629+
'george/*',
630+
[
631+
'before' => [
632+
'foo',
633+
'bar',
634+
],
635+
'after' => ['baz'],
667636
],
668637
],
669-
];
670-
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
671-
$filters = $this->createFilters($filtersConfig);
672-
673-
$uri = 'admin/foo/bar';
674-
$expected = [
675-
'before' => [
676-
'foo',
677-
'bar',
638+
'empty array not exclude' => [
639+
'admin/foo/bar',
640+
[],
641+
[
642+
'before' => [
643+
'foo',
644+
'bar',
645+
],
646+
'after' => ['baz'],
647+
],
678648
],
679-
'after' => ['baz'],
680649
];
681-
$this->assertSame($expected, $filters->initialize($uri)->getFilters());
682650
}
683651

684652
public function testAfterExceptString(): void

0 commit comments

Comments
 (0)