", $class->description); } - /** - * @dataProvider filterChildClassDataProvider - */ + #[DataProvider('filterChildClassDataProvider')] public function testFilterWithParent(Filter $filter, $class): void { $class->name = "Sir Isaac Newton"; @@ -55,9 +52,7 @@ public function testFilterWithParent(Filter $filter, $class): void $this->assertStringNotContainsString(" ", $class->surname); } - /** - * @dataProvider filterClassDataProvider - */ + #[DataProvider('filterClassDataProvider')] public function testFilterProperty(Filter $filter, $class): void { $class->name = "Sir Isaac Newton"; @@ -74,9 +69,7 @@ public function testFilterProperty(Filter $filter, $class): void $this->assertStringNotContainsString("
", $class->description); } - /** - * @dataProvider filterDataProvider - */ + #[DataProvider('filterDataProvider')] public function testFilterValue(Filter $filter): void { $value = "this is a string
with tags
and malformed"; @@ -89,9 +82,7 @@ public function testFilterValue(Filter $filter): void $this->assertStringNotContainsString('', $filtered); } - /** - * @dataProvider filterDataProvider - */ + #[DataProvider('filterDataProvider')] public function testFilterValueWithArray(Filter $filter): void { $value = "this is a string
with tags
and\n malformed"; @@ -106,57 +97,39 @@ public function testFilterValueWithArray(Filter $filter): void $this->assertStringNotContainsString('\n', $filtered); } - /** - * @dataProvider filterDataProvider - */ + #[DataProvider('filterDataProvider')] public function testNotFailOnNull(Filter $filter): void { $this->expectNotToPerformAssertions(); $filter->filterEntity(null); } - /** - * @dataProvider filterDataProvider - */ + #[DataProvider('filterDataProvider')] public function testGetMetadataFactory(Filter $filter): void { $this->assertInstanceOf(ClassMetadataFactory::class, $filter->getMetadataFactory()); } - - public function filterClassDataProvider(): Generator - { - yield 'Annotation' => [ - new Filter($this->buildMetadataFactoryWithAnnotationLoader(), new FilterLoader()), - new Dummy\Classes\AnnotatedClass(), - ]; + public static function filterClassDataProvider(): Generator + { yield 'Attribute' => [ - new Filter($this->buildMetadataFactoryWithAttributeLoader(), new FilterLoader()), + new Filter(self::buildMetadataFactoryWithAttributeLoader(), new FilterLoader()), new Dummy\Classes\AttributedClass(), ]; } - public function filterChildClassDataProvider(): Generator + public static function filterChildClassDataProvider(): Generator { - yield 'Annotation' => [ - new Filter($this->buildMetadataFactoryWithAnnotationLoader(), new FilterLoader()), - new Dummy\Classes\ChildAnnotatedClass(), - ]; - yield 'Attribute' => [ - new Filter($this->buildMetadataFactoryWithAttributeLoader(), new FilterLoader()), + new Filter(self::buildMetadataFactoryWithAttributeLoader(), new FilterLoader()), new Dummy\Classes\ChildAttributedClass(), ]; } - - public function filterDataProvider(): Generator - { - yield 'Annotation' => [ - new Filter($this->buildMetadataFactoryWithAnnotationLoader(), new FilterLoader()), - ]; + public static function filterDataProvider(): Generator + { yield 'Attribute' => [ - new Filter($this->buildMetadataFactoryWithAttributeLoader(), new FilterLoader()), + new Filter(self::buildMetadataFactoryWithAttributeLoader(), new FilterLoader()), ]; } } diff --git a/tests/DMS/Filter/Filters/AlnumTest.php b/tests/DMS/Filter/Filters/AlnumTest.php index d34ea02..ef197bf 100644 --- a/tests/DMS/Filter/Filters/AlnumTest.php +++ b/tests/DMS/Filter/Filters/AlnumTest.php @@ -4,24 +4,18 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\Alnum as AlnumRule; +use PHPUnit\Framework\Attributes\DataProvider; +use ReflectionException; use ReflectionProperty; class AlnumTest extends FilterTestCase { - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - * @param null $unicodeSetting - * - * @throws \ReflectionException + * @throws ReflectionException */ - public function testRule($options, $value, $expectedResult, $unicodeSetting = null): void + #[DataProvider('provideForRule')] + public function testRule(AlnumRule $rule, $value, $expectedResult, $unicodeSetting = null): void { - $rule = new AlnumRule($options); $filter = new Alnum(); if ($unicodeSetting !== null) { @@ -35,26 +29,26 @@ public function testRule($options, $value, $expectedResult, $unicodeSetting = nu $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [false, "My Text", "MyText", true], - [false, "My Text", "MyText", false], - [true, "My Text", "My Text", true], - [true, "My Text", "My Text", false], - [true, "My Text!", "My Text", true], - [true, "My Text!", "My Text", false], - [true, "My Text21!", "My Text21", true], - [true, "My Text21!", "My Text21", false], - [true, "João Sorrisão", "João Sorrisão", true], - [true, "João Sorrisão", "Joo Sorriso", false], - [true, "GRΣΣK", "GRΣΣK", true], - [true, "GRΣΣK", "GRK", false], - [true, "Helgi Þormar Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], - [true, "Helgi Þormar Þorbjörnsson", "Helgi ormar orbjrnsson", false], - [true, "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], - [true, "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi ormar orbjrnsson", false], - [true, null, null, false], + [new AlnumRule(false), "My Text", "MyText", true], + [new AlnumRule(false), "My Text", "MyText", false], + [new AlnumRule(true), "My Text", "My Text", true], + [new AlnumRule(true), "My Text", "My Text", false], + [new AlnumRule(true), "My Text!", "My Text", true], + [new AlnumRule(true), "My Text!", "My Text", false], + [new AlnumRule(true), "My Text21!", "My Text21", true], + [new AlnumRule(true), "My Text21!", "My Text21", false], + [new AlnumRule(true), "João Sorrisão", "João Sorrisão", true], + [new AlnumRule(true), "João Sorrisão", "Joo Sorriso", false], + [new AlnumRule(true), "GRΣΣK", "GRΣΣK", true], + [new AlnumRule(true), "GRΣΣK", "GRK", false], + [new AlnumRule(true), "Helgi Þormar Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], + [new AlnumRule(true), "Helgi Þormar Þorbjörnsson", "Helgi ormar orbjrnsson", false], + [new AlnumRule(true), "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], + [new AlnumRule(true), "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi ormar orbjrnsson", false], + [new AlnumRule(true), null, null, false], ]; } -} +} \ No newline at end of file diff --git a/tests/DMS/Filter/Filters/AlphaTest.php b/tests/DMS/Filter/Filters/AlphaTest.php index 0eb584a..d812ed3 100644 --- a/tests/DMS/Filter/Filters/AlphaTest.php +++ b/tests/DMS/Filter/Filters/AlphaTest.php @@ -4,24 +4,18 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\Alpha as AlphaRule; +use PHPUnit\Framework\Attributes\DataProvider; +use ReflectionException; use ReflectionProperty; class AlphaTest extends FilterTestCase { - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - * @param null $unicodeSetting - * - * @throws \ReflectionException + * @throws ReflectionException */ - public function testRule($options, $value, $expectedResult, $unicodeSetting = null): void + #[DataProvider('provideForRule')] + public function testRule(AlphaRule $rule, $value, $expectedResult, $unicodeSetting = null): void { - $rule = new AlphaRule($options); $filter = new Alpha(); if ($unicodeSetting !== null) { @@ -35,24 +29,24 @@ public function testRule($options, $value, $expectedResult, $unicodeSetting = nu $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [false, "My Text", "MyText", true], - [false, "My Text", "MyText", false], - [true, "My Text", "My Text", true], - [true, "My Text", "My Text", false], - [true, "My Text!", "My Text", true], - [true, "My Text!", "My Text", false], - [true, "My Text21!", "My Text", true], - [true, "My Text21!", "My Text", false], - [true, "João 2Sorrisão", "João Sorrisão", true], - [true, "João 2Sorrisão", "Joo Sorriso", false], - [true, "Helgi Þormar Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], - [true, "Helgi Þormar Þorbjörnsson", "Helgi ormar orbjrnsson", false], - [true, "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], - [true, "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi ormar orbjrnsson", false], - [true, null, null, false], + [new AlphaRule(false), "My Text", "MyText", true], + [new AlphaRule(false), "My Text", "MyText", false], + [new AlphaRule(true), "My Text", "My Text", true], + [new AlphaRule(true), "My Text", "My Text", false], + [new AlphaRule(true), "My Text!", "My Text", true], + [new AlphaRule(true), "My Text!", "My Text", false], + [new AlphaRule(true), "My Text21!", "My Text", true], + [new AlphaRule(true), "My Text21!", "My Text", false], + [new AlphaRule(true), "João 2Sorrisão", "João Sorrisão", true], + [new AlphaRule(true), "João 2Sorrisão", "Joo Sorriso", false], + [new AlphaRule(true), "Helgi Þormar Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], + [new AlphaRule(true), "Helgi Þormar Þorbjörnsson", "Helgi ormar orbjrnsson", false], + [new AlphaRule(true), "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi Þormar Þorbjörnsson", true], + [new AlphaRule(true), "Helgi Þormar!@#$&*( )(*&%$#@Þorbjörnsson", "Helgi ormar orbjrnsson", false], + [new AlphaRule(true), null, null, false], ]; } -} +} \ No newline at end of file diff --git a/tests/DMS/Filter/Filters/BooleanTest.php b/tests/DMS/Filter/Filters/BooleanTest.php index a5aa79b..4a61956 100644 --- a/tests/DMS/Filter/Filters/BooleanTest.php +++ b/tests/DMS/Filter/Filters/BooleanTest.php @@ -4,20 +4,13 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\BooleanScalar as BooleanRule; +use PHPUnit\Framework\Attributes\DataProvider; class BooleanTest extends FilterTestCase { - - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - */ - public function testRule($options, $value, $expectedResult): void + #[DataProvider('provideForRule')] + public function testRule(BooleanRule $rule, $value, $expectedResult): void { - $rule = new BooleanRule($options); $filter = new BooleanScalar(); $result = $filter->apply($rule, $value); @@ -25,15 +18,15 @@ public function testRule($options, $value, $expectedResult): void $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [null, "My Text", true], - [null, "", false], - [null, null, false], - [null, 21.9, true], - [null, 21, true], - [null, 0, false], + [new BooleanRule(), "My Text", true], + [new BooleanRule(), "", false], + [new BooleanRule(), null, false], + [new BooleanRule(), 21.9, true], + [new BooleanRule(), 21, true], + [new BooleanRule(), 0, false], ]; } -} +} \ No newline at end of file diff --git a/tests/DMS/Filter/Filters/CallbackTest.php b/tests/DMS/Filter/Filters/CallbackTest.php index cf356da..c4be536 100644 --- a/tests/DMS/Filter/Filters/CallbackTest.php +++ b/tests/DMS/Filter/Filters/CallbackTest.php @@ -4,28 +4,21 @@ use DMS\Filter\Exception\FilterException; use DMS\Filter\Exception\InvalidCallbackException; -use DMS\Tests\Dummy\Classes\AnnotatedClass; +use DMS\Tests\Dummy\Classes\AttributedClass; use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\Callback as CallbackRule; use PHPUnit\Framework\MockObject\MockObject; class CallbackTest extends FilterTestCase { - /** - * @var CallbackRule|MockObject - */ - protected $rule; - - /** - * @var Callback - */ - protected $filter; + protected MockObject|CallbackRule $rule; + protected Callback $filter; public function setUp(): void -{ + { parent::setUp(); - $this->rule = $this->getMockBuilder(CallbackRule::class)->getMock(); + $this->rule = $this->getMockBuilder(CallbackRule::class)->disableOriginalConstructor()->getMock(); $this->filter = new Callback(); } @@ -36,7 +29,7 @@ public function testRuleWithObjectMethod(): void ); $this->rule->callback = 'callbackMethod'; - $obj = new AnnotatedClass(); + $obj = new AttributedClass(); $this->filter->setCurrentObject($obj); $result = $this->filter->apply($this->rule, 'value'); @@ -52,7 +45,7 @@ public function testRuleWithObjectMethodInvalid(): void ); $this->rule->callback = 'callbackMissingMethod'; - $obj = new AnnotatedClass(); + $obj = new AttributedClass(); $this->filter->setCurrentObject($obj); $this->filter->apply($this->rule, 'value'); @@ -74,7 +67,7 @@ public function testRuleWithCallable(): void $this->rule->expects($this->once())->method('getInputType')->willReturn( CallbackRule::CALLABLE_TYPE ); - $this->rule->callback = [AnnotatedClass::class, 'anotherCallback']; + $this->rule->callback = [AttributedClass::class, 'anotherCallback']; $result = $this->filter->apply($this->rule, 'value'); @@ -86,7 +79,7 @@ public function testRuleWithNonStaticCallable(): void $this->rule->expects($this->once())->method('getInputType')->willReturn( CallbackRule::CALLABLE_TYPE ); - $this->rule->callback = [new AnnotatedClass(), 'callbackMethod']; + $this->rule->callback = [new AttributedClass(), 'callbackMethod']; $result = $this->filter->apply($this->rule, 'value'); @@ -99,14 +92,14 @@ public function testRuleWithCallableInvalid(): void $this->rule->expects($this->once())->method('getInputType')->willReturn( CallbackRule::CALLABLE_TYPE ); - $this->rule->callback = [AnnotatedClass::class, 'callbackMissingMethod']; + $this->rule->callback = [AttributedClass::class, 'callbackMissingMethod']; - $result = $this->filter->apply($this->rule, 'value'); + $this->filter->apply($this->rule, 'value'); } public function testRuleWithClosure(): void { - $closure = static function ($value) { + $closure = static function () { return 'called_back'; }; @@ -128,6 +121,6 @@ public function testRuleWithNonClosure(): void ); $this->rule->callback = "i'm not a closure"; - $result = $this->filter->apply($this->rule, 'value'); + $this->filter->apply($this->rule, 'value'); } } diff --git a/tests/DMS/Filter/Filters/DigitsTest.php b/tests/DMS/Filter/Filters/DigitsTest.php index ed7aabe..eff717e 100644 --- a/tests/DMS/Filter/Filters/DigitsTest.php +++ b/tests/DMS/Filter/Filters/DigitsTest.php @@ -4,24 +4,18 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\Digits as DigitsRule; +use PHPUnit\Framework\Attributes\DataProvider; +use ReflectionException; use ReflectionProperty; class DigitsTest extends FilterTestCase { - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - * @param null $unicodeSetting - * - * @throws \ReflectionException + * @throws ReflectionException */ - public function testRule($options, $value, $expectedResult, $unicodeSetting = null): void + #[DataProvider('provideForRule')] + public function testRule(DigitsRule $rule, $value, $expectedResult, $unicodeSetting = null): void { - $rule = new DigitsRule($options); $filter = new Digits(); if ($unicodeSetting !== null) { @@ -35,21 +29,21 @@ public function testRule($options, $value, $expectedResult, $unicodeSetting = nu $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [false, "My Text", ""], - [false, "001 t55", "00155"], - [true, "My 23 dogs", " 23 "], - [false, "My 23 dogs", "23"], - [true, "233 055", "233 055", true], - [true, "233 055", "233 055", false], - [true, "233 t055s", "233 055"], - [true, "My Text21!", " 21"], //TODO verify this. - [true, "João Sorrisão", " ", true], - [true, "João Sorrisão", " ", false], - [true, "001Helgi Þormar Þorbjörnsson", "001 ", true], - [true, "001Helgi Þormar Þorbjörnsson", "001 ", false], + [new DigitsRule(false), "My Text", ""], + [new DigitsRule(false), "001 t55", "00155"], + [new DigitsRule(true), "My 23 dogs", " 23 "], + [new DigitsRule(false), "My 23 dogs", "23"], + [new DigitsRule(true), "233 055", "233 055", true], + [new DigitsRule(true), "233 055", "233 055", false], + [new DigitsRule(true), "233 t055s", "233 055"], + [new DigitsRule(true), "My Text21!", " 21"], //TODO verify this. + [new DigitsRule(true), "João Sorrisão", " ", true], + [new DigitsRule(true), "João Sorrisão", " ", false], + [new DigitsRule(true), "001Helgi Þormar Þorbjörnsson", "001 ", true], + [new DigitsRule(true), "001Helgi Þormar Þorbjörnsson", "001 ", false], ]; } -} +} \ No newline at end of file diff --git a/tests/DMS/Filter/Filters/FloatTest.php b/tests/DMS/Filter/Filters/FloatTest.php index 2391f00..ccfb7d9 100644 --- a/tests/DMS/Filter/Filters/FloatTest.php +++ b/tests/DMS/Filter/Filters/FloatTest.php @@ -4,20 +4,13 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\FloatScalar as FloatRule; +use PHPUnit\Framework\Attributes\DataProvider; class FloatTest extends FilterTestCase { - - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - */ - public function testRule($options, $value, $expectedResult): void + #[DataProvider('provideForRule')] + public function testRule(FloatRule $rule, $value, $expectedResult): void { - $rule = new FloatRule($options); $filter = new FloatScalar(); $result = $filter->apply($rule, $value); @@ -25,13 +18,13 @@ public function testRule($options, $value, $expectedResult): void $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [null, "My Text", 0.0], - [null, "21", 21.0], - [null, "21.2", 21.2], - [null, 21.9, 21.9], + [new FloatRule(), "My Text", 0.0], + [new FloatRule(), "21", 21.0], + [new FloatRule(), "21.2", 21.2], + [new FloatRule(), 21.9, 21.9], ]; } -} +} \ No newline at end of file diff --git a/tests/DMS/Filter/Filters/HtmlEntitiesTest.php b/tests/DMS/Filter/Filters/HtmlEntitiesTest.php index e9bd660..2342337 100644 --- a/tests/DMS/Filter/Filters/HtmlEntitiesTest.php +++ b/tests/DMS/Filter/Filters/HtmlEntitiesTest.php @@ -4,20 +4,13 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\HtmlEntities as HtmlEntitiesRule; +use PHPUnit\Framework\Attributes\DataProvider; class HtmlEntitiesTest extends FilterTestCase { - - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - */ - public function testRule($options, $value, $expectedResult): void + #[DataProvider('provideForRule')] + public function testRule(HtmlEntitiesRule $rule, $value, $expectedResult): void { - $rule = new HtmlEntitiesRule($options); $filter = new HtmlEntities(); $result = $filter->apply($rule, $value); @@ -25,15 +18,15 @@ public function testRule($options, $value, $expectedResult): void $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [[], "This is some téxt &", "This is some téxt &"], - [[], "This & is a &", "This & is a &"], - [['doubleEncode' => false], "This & is a &", "This & is a &"], - [['flags' => ENT_IGNORE], "With '\" quotes", "With '\" quotes"], - [[], "With '\" quotes", "With '" quotes"], - [['flags' => ENT_QUOTES], "With '\" quotes", "With '" quotes"], + [new HtmlEntitiesRule(), "This is some téxt &", "This is some téxt &"], + [new HtmlEntitiesRule(), "This & is a &", "This & is a &"], + [new HtmlEntitiesRule(doubleEncode: false), "This & is a &", "This & is a &"], + [new HtmlEntitiesRule(flags : ENT_IGNORE), "With '\" quotes", "With '\" quotes"], + [new HtmlEntitiesRule(), "With '\" quotes", "With '" quotes"], + [new HtmlEntitiesRule(flags :ENT_QUOTES), "With '\" quotes", "With '" quotes"], ]; } } diff --git a/tests/DMS/Filter/Filters/IntTest.php b/tests/DMS/Filter/Filters/IntTest.php index bf4851e..daeaf52 100644 --- a/tests/DMS/Filter/Filters/IntTest.php +++ b/tests/DMS/Filter/Filters/IntTest.php @@ -4,20 +4,13 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\IntScalar as IntRule; +use PHPUnit\Framework\Attributes\DataProvider; class IntTest extends FilterTestCase { - - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - */ - public function testRule($options, $value, $expectedResult): void + #[DataProvider('provideForRule')] + public function testRule(IntRule $rule, $value, $expectedResult): void { - $rule = new IntRule($options); $filter = new IntScalar(); $result = $filter->apply($rule, $value); @@ -25,16 +18,16 @@ public function testRule($options, $value, $expectedResult): void $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [null, "My Text", 0], - [null, true, 1], - [null, "21", 21], - [null, "21.2", 21], - [null, "21.9", 21], - [null, 21.9, 21], - [null, null, null], + [new IntRule(), "My Text", 0], + [new IntRule(), true, 1], + [new IntRule(), "21", 21], + [new IntRule(), "21.2", 21], + [new IntRule(), "21.9", 21], + [new IntRule(), 21.9, 21], + [new IntRule(), null, null], ]; } -} +} \ No newline at end of file diff --git a/tests/DMS/Filter/Filters/LaminasTest.php b/tests/DMS/Filter/Filters/LaminasTest.php index a4e5cc8..96b775a 100644 --- a/tests/DMS/Filter/Filters/LaminasTest.php +++ b/tests/DMS/Filter/Filters/LaminasTest.php @@ -1,29 +1,36 @@ buildRule('Boolean', ['casting' => false]); + $rule = $this->buildRule( + 'Laminas\Filter\DenyList', + ['list' => ['blocked@example.com', 'spam@example.com']] + ); + $filter = new Laminas(); - $filter->apply($rule, '0'); - $this->expectNotToPerformAssertions(); + $this->assertTrue(!is_null($filter->apply($rule, 'billy@example.com'))); + $this->assertTrue(is_null($filter->apply($rule, 'blocked@example.com'))); + $this->assertTrue(!is_null($filter->apply($rule, 'menphis@example.com'))); + $this->assertTrue(is_null($filter->apply($rule, 'spam@example.com'))); + $this->assertTrue(!is_null($filter->apply($rule, 'spam12@example.com'))); } - public function testFilterFullname(): void + public function testFilterBaseName(): void { - $rule = $this->buildRule('Laminas\Filter\Boolean', ['casting' => false]); + $rule = $this->buildRule('Laminas\Filter\BaseName'); $filter = new Laminas(); - $filter->apply($rule, '0'); - $this->expectNotToPerformAssertions(); + $this->assertSame('file.txt', $filter->apply($rule, '/path/to/file.txt')); } public function testInvalidFilter(): void @@ -36,11 +43,6 @@ public function testInvalidFilter(): void protected function buildRule($class, $options = []): LaminasRule { - return new LaminasRule( - [ - 'class' => $class, - 'laminasOptions' => $options, - ] - ); + return new LaminasRule($class, $options); } } diff --git a/tests/DMS/Filter/Filters/Loader/FilterLoaderTest.php b/tests/DMS/Filter/Filters/Loader/FilterLoaderTest.php index b7b3171..6d366e3 100644 --- a/tests/DMS/Filter/Filters/Loader/FilterLoaderTest.php +++ b/tests/DMS/Filter/Filters/Loader/FilterLoaderTest.php @@ -5,6 +5,7 @@ use DMS\Filter\Rules\StripTags; use DMS\Tests\Dummy\Rules\NoOptionsRule; use DMS\Tests\FilterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use UnexpectedValueException; class FilterLoaderTest extends FilterTestCase @@ -12,19 +13,13 @@ class FilterLoaderTest extends FilterTestCase protected FilterLoaderInterface $loader; public function setUp(): void -{ + { parent::setUp(); $this->loader = new FilterLoader(); } - /** - * @param $rule - * @param $return - * @param $expectException - * - * @dataProvider provideForGetFilter - */ + #[DataProvider('provideForGetFilter')] public function testGetFilterForRule($rule, $return, $expectException): void { if ($expectException) { @@ -34,7 +29,7 @@ public function testGetFilterForRule($rule, $return, $expectException): void $this->assertEquals($return, $this->loader->getFilterForRule($rule)); } - public function provideForGetFilter(): array + public static function provideForGetFilter(): array { return [ [new StripTags(), new \DMS\Filter\Filters\StripTags(), false], diff --git a/tests/DMS/Filter/Filters/PregReplaceTest.php b/tests/DMS/Filter/Filters/PregReplaceTest.php index 72a195c..260d2a8 100644 --- a/tests/DMS/Filter/Filters/PregReplaceTest.php +++ b/tests/DMS/Filter/Filters/PregReplaceTest.php @@ -4,20 +4,13 @@ use DMS\Tests\FilterTestCase; use DMS\Filter\Rules\PregReplace as PregReplaceRule; +use PHPUnit\Framework\Attributes\DataProvider; class PregReplaceTest extends FilterTestCase { - - /** - * @dataProvider provideForRule - * - * @param $options - * @param $value - * @param $expectedResult - */ - public function testRule($options, $value, $expectedResult): void + #[DataProvider('provideForRule')] + public function testRule(PregReplaceRule $rule, $value, $expectedResult): void { - $rule = new PregReplaceRule($options); $filter = new PregReplace(); $result = $filter->apply($rule, $value); @@ -25,14 +18,16 @@ public function testRule($options, $value, $expectedResult): void $this->assertEquals($expectedResult, $result); } - public function provideForRule(): array + public static function provideForRule(): array { return [ - [['regexp' => '/(old )/'], "the crazy old fox", "the crazy fox"], - [['regexp' => '/(old)/', 'replacement' => 'new'], "the crazy old fox", "the crazy new fox"], - [['regexp' => '/([0-9]*)/'], "this is day 21", "this is day "], - [['regexp' => '/(style=\"[^\"]*\")/'], "