GitCommitTest::invalidGitCommitDataProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Plugins\GitDiffHistoryAnalyser;
6
7
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\InvalidHistoryMarkerException;
8
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\GitDiffHistoryAnalyser\GitCommit;
9
use PHPUnit\Framework\TestCase;
10
11
final class GitCommitTest extends TestCase
12
{
13
    /**
14
     * @return array<string,array{string}>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{string}> at position 6 could not be parsed: Expected ':' at position 6, but found 'string'.
Loading history...
15
     */
16
    public function invalidGitCommitDataProvider(): array
17
    {
18
        return [
19
            'tooShort' => [
20
                '462550d5644312b6757bb89ac85aa8d9590c28d',
21
            ],
22
23
            'tooLong' => [
24
                '43462550d5644312b6757bb89ac85aa8d9590c28d',
25
            ],
26
27
            'invalidCharacters' => [
28
                '43462550d5644312b6757bb89ac85aa8d9590c2x',
29
            ],
30
        ];
31
    }
32
33
    /**
34
     * @dataProvider invalidGitCommitDataProvider
35
     */
36
    public function testValidateInvalidGitCommit(string $invalidCommit): void
37
    {
38
        $this->assertFalse(GitCommit::validateGitSha($invalidCommit));
39
    }
40
41
    /**
42
     * @dataProvider invalidGitCommitDataProvider
43
     */
44
    public function testInvalidGitCommit(string $invalidCommit): void
45
    {
46
        $this->expectException(InvalidHistoryMarkerException::class);
47
        new GitCommit($invalidCommit);
48
    }
49
50
    /**
51
     * @return array<int,array{string}>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<int,array{string}> at position 6 could not be parsed: Expected ':' at position 6, but found 'string'.
Loading history...
52
     */
53
    public function validGitCommitDataProvider(): array
54
    {
55
        return [
56
            [
57
                '462550d5644312b6757bb89ac85aa8d9590c28d7',
58
            ],
59
            [
60
                '30b68f53df4e590657ba5184b1c6013e9a8dad5c',
61
            ],
62
        ];
63
    }
64
65
    /**
66
     * @dataProvider validGitCommitDataProvider
67
     */
68
    public function testValidateValidGitCommit(string $commit): void
69
    {
70
        $this->assertTrue(GitCommit::validateGitSha($commit));
71
    }
72
73
    /**
74
     * @dataProvider validGitCommitDataProvider
75
     */
76
    public function testValidGitCommit(string $commit): void
77
    {
78
        $gitCommit = new GitCommit($commit);
79
        $this->assertEquals($commit, $gitCommit->asString());
80
    }
81
}
82