RevisionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromSha1WithValidSha1() 0 5 1
A testFromSha1WithNewlinesStillProvidesValidSha1() 0 5 1
A invalidRevisionProvider() 0 9 1
A testInvalidSha1Rejected() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\Git;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use Roave\BackwardCompatibility\Git\Revision;
10
use function sha1;
11
use function str_repeat;
12
use function uniqid;
13
14
/**
15
 * @covers \Roave\BackwardCompatibility\Git\Revision
16
 */
17
final class RevisionTest extends TestCase
18
{
19
    public function testFromSha1WithValidSha1() : void
20
    {
21
        $sha1 = sha1(uniqid('sha1', true));
22
23
        self::assertSame($sha1, (string) Revision::fromSha1($sha1));
24
    }
25
26
    public function testFromSha1WithNewlinesStillProvidesValidSha1() : void
27
    {
28
        $sha1 = sha1(uniqid('sha1', true));
29
30
        self::assertSame($sha1, (string) Revision::fromSha1($sha1 . "\n"));
31
    }
32
33
    /**
34
     * @return string[][]
35
     */
36
    public function invalidRevisionProvider() : array
37
    {
38
        return [
39
            [''],
40
            ['a'],
41
            [str_repeat('a', 39)],
42
            [str_repeat('a', 41)],
43
            [' ' . str_repeat('a', 42)],
44
            [str_repeat('a', 42) . ' '],
45
        ];
46
    }
47
48
    /**
49
     * @dataProvider invalidRevisionProvider
50
     */
51
    public function testInvalidSha1Rejected(string $invalidRevision) : void
52
    {
53
        $this->expectException(InvalidArgumentException::class);
54
        Revision::fromSha1($invalidRevision);
55
    }
56
}
57