From 583a684b03cadedc179dfe1c5e27e902dbe5728a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 13:54:21 +0200 Subject: [PATCH] Created SluggerFilterTest --- .../test/Validation/SluggerFilterTest.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 module/Common/test/Validation/SluggerFilterTest.php 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']; + } +}