Passed
Pull Request — master (#50)
by Marco
02:46
created

GetVersionCollectionFromGitRepositoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\Git;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Git\CheckedOutRepository;
9
use Roave\BackwardCompatibility\Git\GetVersionCollectionFromGitRepository;
10
use Symfony\Component\Process\Process;
11
use Version\Version;
12
use function array_map;
13
use function file_put_contents;
14
use function iterator_to_array;
15
use function mkdir;
16
use function sys_get_temp_dir;
17
use function uniqid;
18
19
/**
20
 * @covers \Roave\BackwardCompatibility\Git\GetVersionCollectionFromGitRepository
21
 */
22
final class GetVersionCollectionFromGitRepositoryTest extends TestCase
23
{
24
    /** @var CheckedOutRepository */
25
    private $repoPath;
26
27
    public function setUp() : void
28
    {
29
        $tmpGitRepo = sys_get_temp_dir() . '/api-compare-' . uniqid('tmpGitRepo', true);
30
        mkdir($tmpGitRepo, 0777, true);
31
        (new Process(['git', 'init']))->setWorkingDirectory($tmpGitRepo)->mustRun();
32
        file_put_contents($tmpGitRepo . '/test', uniqid('testContent', true));
33
        (new Process(['git', 'add', '.']))->setWorkingDirectory($tmpGitRepo)->mustRun();
34
        (new Process(['git', 'commit', '-m', '"whatever"']))->setWorkingDirectory($tmpGitRepo)->mustRun();
35
        $this->repoPath = CheckedOutRepository::fromPath($tmpGitRepo);
36
    }
37
38
    public function tearDown() : void
39
    {
40
        (new Process(['rm', '-Rf', (string) $this->repoPath]))->mustRun();
41
    }
42
43
    private function makeTag(string $tagName) : void
44
    {
45
        (new Process(['git', 'tag', $tagName]))->setWorkingDirectory((string) $this->repoPath)->mustRun();
46
    }
47
48
    public function testFromRepository() : void
49
    {
50
        $this->makeTag('1.0.0');
51
52
        self::assertSame(
53
            ['1.0.0'],
54
            array_map(
55
                function (Version $version) {
56
                    return $version->getVersionString();
57
                },
58
                iterator_to_array((new GetVersionCollectionFromGitRepository())->fromRepository($this->repoPath))
59
            )
60
        );
61
    }
62
}
63