Completed
Pull Request — master (#15)
by James
02:25
created

ApiCompareTest::testExecute()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 34
rs 8.8571
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
'from' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit\Framework\MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

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

29
        $input->expects(self::at(0))->method('getArgument')->with(/** @scrutinizer ignore-type */ 'from')->willReturn($fromSha);
Loading history...
Bug introduced by
The method expects() does not exist on Symfony\Component\Console\Input\InputInterface. ( Ignorable by Annotation )

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

29
        $input->/** @scrutinizer ignore-call */ 
30
                expects(self::at(0))->method('getArgument')->with('from')->willReturn($fromSha);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\ApiCompare\Git\PerformCheckoutOfRevision. ( Ignorable by Annotation )

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

35
        $git->/** @scrutinizer ignore-call */ 
36
              expects(self::at(0))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
            ->method('checkout')
37
            ->with($sourceRepository, $fromSha)
0 ignored issues
show
Bug introduced by
$sourceRepository of type Roave\ApiCompare\Git\CheckedOutRepository is incompatible with the type array expected by parameter $arguments of PHPUnit\Framework\MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

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

37
            ->with(/** @scrutinizer ignore-type */ $sourceRepository, $fromSha)
Loading history...
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