|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Core\HistoryAnalyser\UnifiedDiffParser\internal; |
|
6
|
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal\DiffParseException; |
|
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal\FileMutationBuilder; |
|
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal\FileMutationsBuilder; |
|
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal\FindChangeHunkStartState; |
|
11
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal\FindNewFileNameState; |
|
12
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\NewFileName; |
|
13
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\OriginalFileName; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class FindNewFileNameStateTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var OriginalFileName |
|
20
|
|
|
*/ |
|
21
|
|
|
private $originalFileName; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var FindNewFileNameState |
|
25
|
|
|
*/ |
|
26
|
|
|
private $findNewFileNameState; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var FileMutationsBuilder |
|
30
|
|
|
*/ |
|
31
|
|
|
private $fileMutationsBuilder; |
|
32
|
|
|
|
|
33
|
|
|
protected function setUp(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->originalFileName = new OriginalFileName('src/Person.php'); |
|
36
|
|
|
|
|
37
|
|
|
$this->fileMutationsBuilder = new FileMutationsBuilder(); |
|
38
|
|
|
$fileMutationBuilder = new FileMutationBuilder($this->fileMutationsBuilder); |
|
39
|
|
|
$fileMutationBuilder->setOriginalFileName($this->originalFileName); |
|
40
|
|
|
$this->findNewFileNameState = new FindNewFileNameState($fileMutationBuilder); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testNotNewFileName(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->expectException(DiffParseException::class); |
|
46
|
|
|
$this->findNewFileNameState->processLine('similarity index 100%'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testNewFileName(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$newState = $this->findNewFileNameState->processLine(SampleDiffLines::NEW_FILE_NAME); |
|
52
|
|
|
$this->assertInstanceOf(FindChangeHunkStartState::class, $newState); |
|
53
|
|
|
$newState->finish(); |
|
54
|
|
|
|
|
55
|
|
|
$newFileName = new NewFileName('src/Student.php'); |
|
56
|
|
|
|
|
57
|
|
|
$fileMutations = $this->fileMutationsBuilder->build(); |
|
58
|
|
|
$fileMutation = $fileMutations->getFileMutation($newFileName); |
|
59
|
|
|
$this->assertNotNull($fileMutation); |
|
60
|
|
|
$this->assertFalse($fileMutation->isDeletedFile()); |
|
61
|
|
|
$this->assertFalse($fileMutation->isAddedFile()); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals($this->originalFileName, $fileMutation->getOriginalFileName()); |
|
64
|
|
|
$this->assertEquals($newFileName, $fileMutation->getNewFileName()); |
|
65
|
|
|
$this->assertCount(0, $fileMutation->getLineMutations()); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|