1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ComposerRequireCheckerTest\Cli; |
4
|
|
|
|
5
|
|
|
use ComposerRequireChecker\Cli\Application; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
9
|
|
|
|
10
|
|
|
class CheckCommandTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var CommandTester |
15
|
|
|
*/ |
16
|
|
|
private $commandTester; |
17
|
|
|
|
18
|
|
|
public function setUp() |
19
|
|
|
{ |
20
|
|
|
$application = new Application(); |
21
|
|
|
$command = $application->get('check'); |
22
|
|
|
|
23
|
|
|
$this->commandTester = new CommandTester($command); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testExceptionIfComposerJsonNotFound() |
27
|
|
|
{ |
28
|
|
|
self::expectException(\InvalidArgumentException::class); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$this->commandTester->execute([ |
31
|
|
|
'composer-json' => 'this-will-not-be-found.json' |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testSelfCheckShowsNoErrors() |
36
|
|
|
{ |
37
|
|
|
$this->commandTester->execute([ |
38
|
|
|
// that's our own composer.json, lets be sure our self check does not throw errors |
39
|
|
|
'composer-json' => dirname(__DIR__, 3) . '/composer.json' |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
$this->assertSame(0, $this->commandTester->getStatusCode()); |
43
|
|
|
$this->assertContains('no unknown symbols found', $this->commandTester->getDisplay()); |
44
|
|
|
|
45
|
|
|
// verbose output should not be shown |
46
|
|
|
$this->assertNotRegExp('/Collecting defined (vendor|extension) symbols... found \d+ symbols./', $this->commandTester->getDisplay()); |
47
|
|
|
$this->assertNotRegExp('/Collecting used symbols... found \d+ symbols./', $this->commandTester->getDisplay()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testVerboseSelfCheckShowsCounts() |
51
|
|
|
{ |
52
|
|
|
$this->commandTester->execute([ |
53
|
|
|
// that's our own composer.json |
54
|
|
|
'composer-json' => dirname(__DIR__, 3) . '/composer.json', |
55
|
|
|
], [ |
56
|
|
|
'verbosity' => OutputInterface::VERBOSITY_VERBOSE, |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
$this->assertRegExp('/Collecting defined vendor symbols... found \d+ symbols./', $this->commandTester->getDisplay()); |
60
|
|
|
$this->assertRegExp('/Collecting defined extension symbols... found \d+ symbols./', $this->commandTester->getDisplay()); |
61
|
|
|
$this->assertRegExp('/Collecting used symbols... found \d+ symbols./', $this->commandTester->getDisplay()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|