|
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') |
|
|
|
|
|
|
41
|
|
|
->willReturn($hasReturn); |
|
42
|
|
|
$input->expects($hasReturn?$this->once():$this->never()) |
|
43
|
|
|
->method('getOption') |
|
44
|
|
|
->with('register-namespace') |
|
45
|
|
|
->willReturn($return); |
|
46
|
|
|
return $input; |
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |