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