1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Core\HistoryAnalyser\UnifiedDiffParser; |
6
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\FileMutation; |
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\FileMutations; |
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\NewFileName; |
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\OriginalFileName; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
final class FileMutationsTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private const FILE_1_NAME = 'foo/bar.php'; |
16
|
|
|
private const FILE_2_NAME = 'foo/baz.php'; |
17
|
|
|
private const FILE_3_NAME = 'foo/foo.php'; |
18
|
|
|
|
19
|
|
|
public function testHappyPath(): void |
20
|
|
|
{ |
21
|
|
|
$fileMutation1 = new FileMutation( |
22
|
|
|
new OriginalFileName(self::FILE_1_NAME), |
23
|
|
|
new NewFileName(self::FILE_1_NAME), |
24
|
|
|
[], |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$fileMutation2 = new FileMutation( |
28
|
|
|
new OriginalFileName(self::FILE_2_NAME), |
29
|
|
|
new NewFileName(self::FILE_2_NAME), |
30
|
|
|
[], |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$fileMutations = new FileMutations([$fileMutation1, $fileMutation2]); |
34
|
|
|
|
35
|
|
|
$this->assertSame($fileMutation1, $fileMutations->getFileMutation(new NewFileName(self::FILE_1_NAME))); |
36
|
|
|
$this->assertSame($fileMutation2, $fileMutations->getFileMutation(new NewFileName(self::FILE_2_NAME))); |
37
|
|
|
$this->assertNull($fileMutations->getFileMutation(new NewFileName(self::FILE_3_NAME))); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testDuplicateFilesMutationsAdded(): void |
41
|
|
|
{ |
42
|
|
|
$fileMutation1 = new FileMutation( |
43
|
|
|
new OriginalFileName(self::FILE_1_NAME), |
44
|
|
|
new NewFileName(self::FILE_1_NAME), |
45
|
|
|
[], |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$fileMutation2 = new FileMutation( |
49
|
|
|
new OriginalFileName(self::FILE_1_NAME), |
50
|
|
|
new NewFileName(self::FILE_1_NAME), |
51
|
|
|
[], |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->expectException(\InvalidArgumentException::class); |
55
|
|
|
new FileMutations([$fileMutation1, $fileMutation2]); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|