Completed
Push — master ( 4eb33b...9d87b5 )
by Marco
11s queued 10s
created

testFromSha1WithNewlinesStillProvidesValidSha1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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));
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        self::/** @scrutinizer ignore-call */ 
24
              assertSame($sha1, (string) Revision::fromSha1($sha1));
Loading history...
Bug introduced by
$sha1 of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        self::assertSame(/** @scrutinizer ignore-type */ $sha1, (string) Revision::fromSha1($sha1));
Loading history...
24
    }
25
26
    public function testFromSha1WithNewlinesStillProvidesValidSha1() : void
27
    {
28
        $sha1 = sha1(uniqid('sha1', true));
29
30
        self::assertSame($sha1, (string) Revision::fromSha1($sha1 . "\n"));
0 ignored issues
show
Bug introduced by
$sha1 of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        self::assertSame(/** @scrutinizer ignore-type */ $sha1, (string) Revision::fromSha1($sha1 . "\n"));
Loading history...
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        self::/** @scrutinizer ignore-call */ 
31
              assertSame($sha1, (string) Revision::fromSha1($sha1 . "\n"));
Loading history...
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