Passed
Push — master ( 215b59...9cd7ac )
by Marco
38s
created

testVerboseSelfCheckShowsCounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

28
        self::/** @scrutinizer ignore-call */ 
29
              expectException(\InvalidArgumentException::class);
Loading history...
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