|
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}> |
|
|
|
|
|
|
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}> |
|
|
|
|
|
|
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
|
|
|
|