|
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
|
|
|
$this->markTestSkipped(); |
|
32
|
|
|
self::expectException(\InvalidArgumentException::class); |
|
33
|
|
|
|
|
34
|
|
|
$this->commandTester->execute([ |
|
35
|
|
|
'composer-json' => 'this-will-not-be-found.json' |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testSelfCheckShowsNoErrors() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->markTestSkipped(); |
|
42
|
|
|
$this->commandTester->execute([ |
|
43
|
|
|
// that's our own composer.json, lets be sure our self check does not throw errors |
|
44
|
|
|
'composer-json' => dirname(__DIR__, 3) . '/composer.json' |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertSame(0, $this->commandTester->getStatusCode()); |
|
48
|
|
|
$this->assertContains('no unknown symbols found', $this->commandTester->getDisplay()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @test |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testHandleResultForFailure(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$command = new CheckCommand(); |
|
58
|
|
|
$method = new ReflectionMethod($command, 'handleResult'); |
|
59
|
|
|
$method->setAccessible(true); |
|
60
|
|
|
$output = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
61
|
|
|
$printed = []; |
|
62
|
|
|
$output->expects($this->any()) |
|
63
|
|
|
->method('writeln') |
|
64
|
|
|
->willReturnCallback(function ($line) use (&$printed) { |
|
65
|
|
|
if ($line) { |
|
66
|
|
|
$printed[] = $line; |
|
67
|
|
|
} |
|
68
|
|
|
}); |
|
69
|
|
|
$output->expects($this->any()) |
|
70
|
|
|
->method('getFormatter') |
|
71
|
|
|
->with() |
|
72
|
|
|
->willReturn($this->getMockBuilder(OutputFormatterInterface::class)->getMock()); |
|
73
|
|
|
$this->assertEquals(1, $method->invoke( |
|
74
|
|
|
$command, |
|
75
|
|
|
['A_Symbol', 'A\\Nother\\Symbol', 'A_Third\\Symbol'], |
|
76
|
|
|
$output |
|
77
|
|
|
)); |
|
78
|
|
|
$this->assertEquals( |
|
79
|
|
|
[ |
|
80
|
|
|
"The following unknown symbols were found:", |
|
81
|
|
|
"+--+--+", |
|
82
|
|
|
"|<info> unknown symbol </info>|<info> guessed dependency </info>|", |
|
83
|
|
|
"+--+--+", |
|
84
|
|
|
"| A_Symbol | |", |
|
85
|
|
|
"| A\\Nother\\Symbol | |", |
|
86
|
|
|
"| A_Third\\Symbol | |", |
|
87
|
|
|
"+--+--+" |
|
88
|
|
|
], |
|
89
|
|
|
$printed |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|