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

CheckedOutRepositoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromPath() 0 11 1
A testFromPathRejectsNonGitDirectory() 0 5 1
A testFromPathRejectsNonExistingDirectory() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\Git;
6
7
use Assert\AssertionFailedException;
8
use PHPUnit\Framework\TestCase;
9
use Roave\BackwardCompatibility\Git\CheckedOutRepository;
10
use function Safe\mkdir;
11
use function Safe\rmdir;
12
use function sys_get_temp_dir;
13
use function uniqid;
14
15
/**
16
 * @covers \Roave\BackwardCompatibility\Git\CheckedOutRepository
17
 */
18
final class CheckedOutRepositoryTest extends TestCase
19
{
20
    public function testFromPath() : void
21
    {
22
        $path = sys_get_temp_dir() . '/' . uniqid('testPath', true);
23
        mkdir($path, 0777, true);
24
        mkdir($path . '/.git');
25
26
        $checkedOutRepository = CheckedOutRepository::fromPath($path);
27
        self::assertSame($path, (string) $checkedOutRepository);
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

27
        self::/** @scrutinizer ignore-call */ 
28
              assertSame($path, (string) $checkedOutRepository);
Loading history...
Bug introduced by
$path 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

27
        self::assertSame(/** @scrutinizer ignore-type */ $path, (string) $checkedOutRepository);
Loading history...
28
29
        rmdir($path . '/.git');
30
        rmdir($path);
31
    }
32
33
    public function testFromPathRejectsNonGitDirectory() : void
34
    {
35
        $this->expectException(AssertionFailedException::class);
36
37
        CheckedOutRepository::fromPath(__DIR__);
38
    }
39
40
    public function testFromPathRejectsNonExistingDirectory() : void
41
    {
42
        $this->expectException(AssertionFailedException::class);
43
44
        CheckedOutRepository::fromPath(__DIR__ . '/non-existing');
45
    }
46
}
47