|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace RoaveTest\ApiCompare\Command; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
7
|
|
|
use Roave\ApiCompare\Command\ApiCompare; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Roave\ApiCompare\Factory\DirectoryReflectorFactory; |
|
10
|
|
|
use Roave\ApiCompare\Git\CheckedOutRepository; |
|
11
|
|
|
use Roave\ApiCompare\Git\PerformCheckoutOfRevision; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @covers \Roave\ApiCompare\Command\ApiCompare |
|
17
|
|
|
*/ |
|
18
|
|
|
final class ApiCompareTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testExecute() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$sourceRepository = CheckedOutRepository::fromPath(realpath(__DIR__ . '/../../../')); |
|
23
|
|
|
|
|
24
|
|
|
$fromSha = sha1('fromRevision', false); |
|
25
|
|
|
$toSha = sha1('toRevision', false); |
|
26
|
|
|
|
|
27
|
|
|
/** @var InputInterface|MockObject $input */ |
|
28
|
|
|
$input = $this->createMock(InputInterface::class); |
|
29
|
|
|
$input->expects(self::at(0))->method('getArgument')->with('from')->willReturn($fromSha); |
|
|
|
|
|
|
30
|
|
|
$input->expects(self::at(1))->method('getArgument')->with('to')->willReturn($toSha); |
|
31
|
|
|
/** @var OutputInterface|MockObject $output */ |
|
32
|
|
|
$output = $this->createMock(OutputInterface::class); |
|
33
|
|
|
/** @var PerformCheckoutOfRevision|MockObject $git */ |
|
34
|
|
|
$git = $this->createMock(PerformCheckoutOfRevision::class); |
|
35
|
|
|
$git->expects(self::at(0)) |
|
|
|
|
|
|
36
|
|
|
->method('checkout') |
|
37
|
|
|
->with($sourceRepository, $fromSha) |
|
|
|
|
|
|
38
|
|
|
->willReturn($sourceRepository); |
|
39
|
|
|
$git->expects(self::at(1)) |
|
40
|
|
|
->method('checkout') |
|
41
|
|
|
->with($sourceRepository, $toSha) |
|
42
|
|
|
->willReturn($sourceRepository); |
|
43
|
|
|
$git->expects(self::at(2)) |
|
44
|
|
|
->method('remove') |
|
45
|
|
|
->with($sourceRepository); |
|
46
|
|
|
$git->expects(self::at(3)) |
|
47
|
|
|
->method('remove') |
|
48
|
|
|
->with($sourceRepository); |
|
49
|
|
|
|
|
50
|
|
|
$command = new ApiCompare($git, new DirectoryReflectorFactory()); |
|
51
|
|
|
|
|
52
|
|
|
chdir((string)$sourceRepository); |
|
53
|
|
|
$command->execute($input, $output); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|