1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ComposerRequireCheckerTest\Cli; |
4
|
|
|
|
5
|
|
|
use ComposerRequireChecker\Cli\Application; |
6
|
|
|
use ComposerRequireChecker\Cli\CheckCommand; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use ReflectionMethod; |
9
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
12
|
|
|
|
13
|
|
|
class CheckCommandTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var CommandTester |
18
|
|
|
*/ |
19
|
|
|
private $commandTester; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
$application = new Application(); |
24
|
|
|
$command = $application->get('check'); |
25
|
|
|
|
26
|
|
|
$this->commandTester = new CommandTester($command); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testExceptionIfComposerJsonNotFound() |
30
|
|
|
{ |
31
|
|
|
self::expectException(\InvalidArgumentException::class); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->commandTester->execute([ |
34
|
|
|
'composer-json' => 'this-will-not-be-found.json' |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testSelfCheckShowsNoErrors() |
39
|
|
|
{ |
40
|
|
|
$this->commandTester->execute([ |
41
|
|
|
// that's our own composer.json, lets be sure our self check does not throw errors |
42
|
|
|
'composer-json' => dirname(__DIR__, 3) . '/composer.json' |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$this->assertSame(0, $this->commandTester->getStatusCode()); |
46
|
|
|
$this->assertContains('no unknown symbols found', $this->commandTester->getDisplay()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function testHandleResultForFailure(): void |
54
|
|
|
{ |
55
|
|
|
$command = new CheckCommand(); |
56
|
|
|
$method = new ReflectionMethod($command, 'handleResult'); |
57
|
|
|
$method->setAccessible(true); |
58
|
|
|
$output = $this->getMockBuilder(OutputInterface::class)->getMock(); |
59
|
|
|
$printed = []; |
60
|
|
|
$collect = function ($line) use (&$printed) { |
61
|
|
|
if ($line) { |
62
|
|
|
$printed[] = $line; |
63
|
|
|
} |
64
|
|
|
}; |
65
|
|
|
$output->expects($this->any()) |
66
|
|
|
->method('writeln') |
67
|
|
|
->willReturnCallback($collect); |
68
|
|
|
$output->expects($this->any()) |
69
|
|
|
->method('write') |
70
|
|
|
->willReturnCallback($collect); |
71
|
|
|
$output->expects($this->any()) |
72
|
|
|
->method('getFormatter') |
73
|
|
|
->with() |
74
|
|
|
->willReturn($this->getMockBuilder(OutputFormatterInterface::class)->getMock()); |
75
|
|
|
$this->assertEquals(1, $method->invoke( |
76
|
|
|
$command, |
77
|
|
|
['A_Symbol', 'A\\Nother\\Symbol', 'A_Third\\Symbol'], |
78
|
|
|
$output |
79
|
|
|
)); |
80
|
|
|
$this->assertEquals( |
81
|
|
|
[ |
82
|
|
|
"The following unknown symbols were found:", |
83
|
|
|
"+--+--+", |
84
|
|
|
"|<info> unknown symbol </info>|<info> guessed dependency </info>|", |
85
|
|
|
"+--+--+", |
86
|
|
|
"| A_Symbol | |", |
87
|
|
|
"| A\\Nother\\Symbol | |", |
88
|
|
|
"| A_Third\\Symbol | |", |
89
|
|
|
"+--+--+" |
90
|
|
|
], |
91
|
|
|
$printed |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|