1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AHJ\ApprovalTests\Tests\Unit; |
6
|
|
|
|
7
|
|
|
use AHJ\ApprovalTests\FilePathResolver; |
8
|
|
|
use Generator; |
9
|
|
|
use PHPUnit\Framework\Assert; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
final class FilePathResolverTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @dataProvider provideTestFilePath |
16
|
|
|
*/ |
17
|
|
|
public function testGetApprovalFilePath(string $testFilePath, string $expected): void |
18
|
|
|
{ |
19
|
|
|
$actual = (new FilePathResolver())->getApprovalFilePath($testFilePath); |
20
|
|
|
Assert::assertEquals($expected, $actual); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function provideTestFilePath(): Generator |
24
|
|
|
{ |
25
|
|
|
yield 'simple test file path' => [ |
26
|
|
|
'testFilePath' => '/Users/alex/Dev/approval-tests/tests/Example/GildedRoseTest.php', |
27
|
|
|
'expected' => 'tests/Example/approval', |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
yield 'nested test file path' => [ |
31
|
|
|
'testFilePath' => '/Users/alex/Dev/approval-tests/tests/Example/ExtraCase/GildedRoseTest.php', |
32
|
|
|
'expected' => 'tests/Example/ExtraCase/approval', |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider provideTestFileName |
38
|
|
|
*/ |
39
|
|
|
public function testGetTestFileName(string $testFileName, string $testMethodName, string $expected): void |
40
|
|
|
{ |
41
|
|
|
$actual = (new FilePathResolver())->getApprovalFileName($testFileName, $testMethodName); |
42
|
|
|
Assert::assertEquals($expected, $actual); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function provideTestFileName(): Generator |
46
|
|
|
{ |
47
|
|
|
yield 'name in simple test file path' => [ |
48
|
|
|
'testFileName' => '/Users/alex/Dev/approval-tests/tests/Example/GildedRoseTest.php', |
49
|
|
|
'testMethodName' => 'testUpdateQuality', |
50
|
|
|
'expected' => 'GildedRoseTest.testUpdateQuality', |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
yield 'name in nested test file path' => [ |
54
|
|
|
'testFileName' => '/Users/alex/Dev/approval-tests/tests/ExtraCase/Example/ExtraCase/GildedRoseTest.php', |
55
|
|
|
'testMethodName' => 'testFunkyMethodInExtraCase', |
56
|
|
|
'expected' => 'GildedRoseTest.testFunkyMethodInExtraCase', |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|