Completed
Push — master ( 48a936...a8d2d3 )
by Alejandro
13s queued 11s
created

provideValuesToFilterWithCasing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Common\Validation;
6
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Prophecy\ObjectProphecy;
9
use Shlinkio\Shlink\Common\Validation\SluggerFilter;
10
use Symfony\Component\String\Slugger\SluggerInterface;
11
12
use function Symfony\Component\String\u;
13
14
class SluggerFilterTest extends TestCase
15
{
16
    private SluggerFilter $filter;
17
    private ObjectProphecy $slugger;
18
19
    public function setUp(): void
20
    {
21
        $this->slugger = $this->prophesize(SluggerInterface::class);
22
        $this->filter = new SluggerFilter($this->slugger->reveal());
23
    }
24
25
    /**
26
     * @test
27
     * @dataProvider provideValuesToFilter
28
     */
29
    public function providedValueIsFilteredAsExpected(?string $providedValue, ?string $expectedValue): void
30
    {
31
        $slugify = $this->slugger->slug($providedValue)->willReturn(u('slug'));
32
33
        $result = $this->filter->filter($providedValue);
34
35
        $this->assertEquals($expectedValue, $result);
36
        $slugify->shouldHaveBeenCalledTimes($expectedValue !== null ? 1 : 0);
37
    }
38
39
    public function provideValuesToFilter(): iterable
40
    {
41
        yield 'null' => [null, null];
42
        yield 'empty string' => ['', 'slug'];
43
        yield 'not empty string' => ['foo', 'slug'];
44
    }
45
46
    /**
47
     * @test
48
     * @dataProvider provideValuesToFilterWithCasing
49
     */
50
    public function internalSluggerKeepsCasing(string $providedValue, string $expectedValue): void
51
    {
52
        $filter = new SluggerFilter();
53
        $this->assertEquals($expectedValue, $filter->filter($providedValue));
54
    }
55
56
    public function provideValuesToFilterWithCasing(): iterable
57
    {
58
        yield ['FoO baR', 'FoO-baR'];
59
        yield ['  FoO/bar', 'FoO-bar'];
60
        yield ['  FoO/bar  ', 'FoO-bar'];
61
        yield ['foobar  ', 'foobar'];
62
        yield ['fo ob ar  ', 'fo-ob-ar'];
63
        yield ['/', ''];
64
    }
65
}
66