|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Plugins\GitDiffHistoryAnalyser; |
|
6
|
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\ProjectRoot; |
|
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\Parser; |
|
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\GitDiffHistoryAnalyser\DiffHistoryAnalyser; |
|
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\GitDiffHistoryAnalyser\GitCommit; |
|
11
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\GitDiffHistoryAnalyser\GitDiffHistoryFactory; |
|
12
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Assertions\AssertGitCommit; |
|
13
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Plugins\GitDiffHistoryAnalyser\internal\StubGitWrapper; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class GitDiffHistoryFactoryTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
use AssertGitCommit; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var GitDiffHistoryFactory |
|
22
|
|
|
*/ |
|
23
|
|
|
private $gitDiffHistoryFactory; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var StubGitWrapper |
|
27
|
|
|
*/ |
|
28
|
|
|
private $gitWrapper; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ProjectRoot |
|
32
|
|
|
*/ |
|
33
|
|
|
private $projectRoot; |
|
34
|
|
|
|
|
35
|
|
|
protected function setUp(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->gitWrapper = new StubGitWrapper(StubGitWrapper::GIT_SHA_1, ''); |
|
38
|
|
|
$parser = new Parser(); |
|
39
|
|
|
$this->gitDiffHistoryFactory = new GitDiffHistoryFactory($this->gitWrapper, $parser); |
|
40
|
|
|
$this->projectRoot = ProjectRoot::fromProjectRoot('/foo', '/home/sarb'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testNewHistoryAnalyser(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$gitCommit = new GitCommit(StubGitWrapper::GIT_SHA_2); |
|
46
|
|
|
$diffHistoryAnalyser = $this->gitDiffHistoryFactory->newHistoryAnalyser($gitCommit, $this->projectRoot); |
|
47
|
|
|
$this->assertInstanceOf(DiffHistoryAnalyser::class, $diffHistoryAnalyser); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testGetIdentifier(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertSame('git', $this->gitDiffHistoryFactory->getIdentifier()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testNewHistoryMarkerFactory(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$historyMarkerFactory = $this->gitDiffHistoryFactory->newHistoryMarkerFactory(); |
|
58
|
|
|
|
|
59
|
|
|
// To check everything is setup correctly we'll call the newCurrentHistoryMarker |
|
60
|
|
|
// (SHA set in setup method via the StubGitWrapper) |
|
61
|
|
|
$currentCommit = $historyMarkerFactory->newCurrentHistoryMarker($this->projectRoot, false); |
|
62
|
|
|
$this->assertGitCommit(StubGitWrapper::GIT_SHA_1, $currentCommit); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|