Test Failed
Pull Request — master (#67)
by
unknown
03:32
created

CheckCommandGetManualListTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuildManualList() 0 6 1
A provideBuildManualList() 0 10 1
A getInputMockForManualList() 0 13 2
1
<?php
2
3
namespace ComposerRequireCheckerTest\Cli;
4
5
use ComposerRequireChecker\Cli\CheckCommand;
6
use PHPUnit\Framework\TestCase;
7
use ReflectionClass;
8
use ReflectionMethod;
9
use Symfony\Component\Console\Input\InputInterface;
10
11
class CheckCommandGetManualListTest extends TestCase
12
{
13
    /**
14
     * @return array
15
     */
16
    public function provideBuildManualList():array
17
    {
18
        $method = (new ReflectionClass(CheckCommand::class))->getMethod('buildManualList');
19
        $method->setAccessible(true);
20
        return [
21
            [$this->getInputMockForManualList(), $method, []],
22
            [$this->getInputMockForManualList(
23
                ['abc', 'nope', 'abc/hi:Abc\\:src', 'abc/def/qoi:Qui\\:src/lib/ext', 'abc/def/:Qui\\:src/lib/ext']),
24
                $method,
25
                ['abc/def/qoi', 'abc/hi']
26
            ],
27
        ];
28
    }
29
30
    /**
31
     * @param array $return
32
     * @return InputInterface
33
     */
34
    private function getInputMockForManualList(array $return = [])
35
    {
36
        $input = $this->getMockBuilder(InputInterface::class)->getMock();
37
        $hasReturn = count($return)>0;
38
        $input->expects($this->once())
39
            ->method('hasOption')
40
            ->with('register-namespace')
0 ignored issues
show
Bug introduced by
'register-namespace' 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

40
            ->with(/** @scrutinizer ignore-type */ 'register-namespace')
Loading history...
41
            ->willReturn($hasReturn);
42
        $input->expects($hasReturn?$this->once():$this->never())
43
            ->method('getOption')
44
            ->with('register-namespace')
45
            ->willReturn($return);
46
        return $input;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $input returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the documented return type Symfony\Component\Console\Input\InputInterface.
Loading history...
47
    }
48
49
    /**
50
     * Since the command does so much, there's no reasonable way to supply test data
51
     * @test
52
     */
53
    public function testBuildManualList(InputInterface $input, ReflectionMethod $method, array $expected)
54
    {
55
        $instance = new CheckCommand();
56
        $result = $method->invoke($instance, $input, __FILE__);
57
        $this->assertCount(count($expected), $result);
58
        $this->assertCount(0, array_diff(array_keys($result), $expected));
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type Countable and Traversable; however, parameter $input of array_keys() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

58
        $this->assertCount(0, array_diff(array_keys(/** @scrutinizer ignore-type */ $result), $expected));
Loading history...
59
    }
60
}