diff --git a/module/Common/test/Validation/SluggerFilterTest.php b/module/Common/test/Validation/SluggerFilterTest.php new file mode 100644 index 00000000..0c02982f --- /dev/null +++ b/module/Common/test/Validation/SluggerFilterTest.php @@ -0,0 +1,44 @@ +slugger = $this->prophesize(SlugifyInterface::class); + $this->filter = new SluggerFilter($this->slugger->reveal()); + } + + /** + * @test + * @dataProvider provideValuesToFilter + */ + public function providedValueIsFilteredAsExpected($providedValue, $expectedValue): void + { + $slugify = $this->slugger->slugify($providedValue)->willReturn('slug'); + + $result = $this->filter->filter($providedValue); + + $this->assertEquals($expectedValue, $result); + $slugify->shouldHaveBeenCalledTimes($expectedValue !== null ? 1 : 0); + } + + public function provideValuesToFilter(): iterable + { + yield 'null' => [null, null]; + yield 'empty string' => ['', null]; + yield 'not empty string' => ['foo', 'slug']; + } +}