Passed
Push — main ( 53ac6e...e37cca )
by Chema
01:30 queued 15s
created

FilenameSanitizerTest::test_factory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Console\Domain\FilenameSanitizer;
6
7
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer;
8
use PHPUnit\Framework\Attributes\DataProvider;
9
use PHPUnit\Framework\TestCase;
10
11
final class FilenameSanitizerTest extends TestCase
12
{
13
    private FilenameSanitizer $filenameSanitizer;
14
15
    protected function setUp(): void
16
    {
17
        $this->filenameSanitizer = new FilenameSanitizer();
18
    }
19
20
    public function test_expected_filenames(): void
21
    {
22
        $actual = implode(', ', $this->filenameSanitizer->getExpectedFilenames());
23
24
        self::assertSame('Facade, Factory, Config, Provider', $actual);
25
    }
26
27
    public function test_facade_or_factory_problem(): void
28
    {
29
        $this->expectExceptionMessage('When using "fac", which filename do you mean [Facade or Factory]?');
30
        $this->filenameSanitizer->sanitize('fac');
31
    }
32
33
    #[DataProvider('providerFacade')]
34
    public function test_facade(string $filename): void
35
    {
36
        self::assertSame(
37
            FilenameSanitizer::FACADE,
38
            $this->filenameSanitizer->sanitize($filename),
39
        );
40
    }
41
42
    public static function providerFacade(): iterable
43
    {
44
        yield ['faca'];
45
        yield ['facad'];
46
        yield ['facade'];
47
        yield ['Facade'];
48
        yield ['cade'];
49
    }
50
51
    /**
52
     * @dataProvider providerFactory
53
     */
54
    public function test_factory(string $filename): void
55
    {
56
        self::assertSame(
57
            FilenameSanitizer::FACTORY,
58
            $this->filenameSanitizer->sanitize($filename),
59
        );
60
    }
61
62
    public static function providerFactory(): iterable
63
    {
64
        yield ['fact'];
65
        yield ['facto'];
66
        yield ['factor'];
67
        yield ['factory'];
68
        yield ['Factory'];
69
        yield ['tory'];
70
    }
71
72
    /**
73
     * @dataProvider providerConfig
74
     */
75
    public function test_config(string $filename): void
76
    {
77
        self::assertSame(
78
            FilenameSanitizer::CONFIG,
79
            $this->filenameSanitizer->sanitize($filename),
80
        );
81
    }
82
83
    public static function providerConfig(): iterable
84
    {
85
        yield ['conf'];
86
        yield ['confi'];
87
        yield ['config'];
88
        yield ['Config'];
89
        yield ['fig'];
90
    }
91
92
    /**
93
     * @dataProvider provideProvider
94
     */
95
    public function test_dependency_provider(string $filename): void
96
    {
97
        self::assertSame(
98
            FilenameSanitizer::PROVIDER,
99
            $this->filenameSanitizer->sanitize($filename),
100
        );
101
    }
102
103
    public static function provideProvider(): iterable
104
    {
105
        yield ['pro'];
106
        yield ['provider'];
107
        yield ['de-pr'];
108
        yield ['provider'];
109
    }
110
}
111