GitDiffHistoryFactoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 47
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testNewHistoryMarkerFactory() 0 8 1
A setUp() 0 6 1
A testNewHistoryAnalyser() 0 5 1
A testGetIdentifier() 0 3 1
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