Passed
Push — master ( 832281...8dd46e )
by Marco
01:34 queued 11s
created

CheckCommandTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 6
eloc 38
c 5
b 0
f 0
dl 0
loc 88
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testVerboseSelfCheckShowsCounts() 0 12 1
A setUp() 0 6 1
A testExceptionIfComposerJsonNotFound() 0 6 1
A testSelfCheckShowsNoErrors() 0 13 1
A testWithAdditionalSourceFiles() 0 19 1
A testSourceFileThatUsesDevDependency() 0 13 1
1
<?php
2
3
namespace ComposerRequireCheckerTest\Cli;
4
5
use ComposerRequireChecker\Cli\Application;
6
use org\bovigo\vfs\vfsStream;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Tester\CommandTester;
10
11
final class CheckCommandTest extends TestCase
12
{
13
14
    /**
15
     * @var CommandTester
16
     */
17
    private $commandTester;
18
19
    protected function setUp(): void
20
    {
21
        $application = new Application();
22
        $command = $application->get('check');
23
24
        $this->commandTester = new CommandTester($command);
25
    }
26
27
    public function testExceptionIfComposerJsonNotFound(): void
28
    {
29
        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

29
        self::/** @scrutinizer ignore-call */ 
30
              expectException(\InvalidArgumentException::class);
Loading history...
30
31
        $this->commandTester->execute([
32
            'composer-json' => 'this-will-not-be-found.json'
33
        ]);
34
    }
35
36
    public function testSelfCheckShowsNoErrors(): void
37
    {
38
        $this->commandTester->execute([
39
            // that's our own composer.json, lets be sure our self check does not throw errors
40
            'composer-json' => dirname(__DIR__, 3) . '/composer.json'
41
        ]);
42
43
        $this->assertSame(0, $this->commandTester->getStatusCode());
44
        $this->assertStringContainsString('no unknown symbols found', $this->commandTester->getDisplay());
45
46
        // verbose output should not be shown
47
        $this->assertNotRegExp('/Collecting defined (vendor|extension) symbols... found \d+ symbols./', $this->commandTester->getDisplay());
48
        $this->assertNotRegExp('/Collecting used symbols... found \d+ symbols./', $this->commandTester->getDisplay());
49
    }
50
51
    public function testVerboseSelfCheckShowsCounts(): void
52
    {
53
        $this->commandTester->execute([
54
            // that's our own composer.json
55
            'composer-json' => dirname(__DIR__, 3) . '/composer.json',
56
        ], [
57
            'verbosity' => OutputInterface::VERBOSITY_VERBOSE,
58
        ]);
59
60
        $this->assertRegExp('/Collecting defined vendor symbols... found \d+ symbols./', $this->commandTester->getDisplay());
61
        $this->assertRegExp('/Collecting defined extension symbols... found \d+ symbols./', $this->commandTester->getDisplay());
62
        $this->assertRegExp('/Collecting used symbols... found \d+ symbols./', $this->commandTester->getDisplay());
63
    }
64
65
    public function testWithAdditionalSourceFiles(): void
66
    {
67
        $root = vfsStream::setup();
68
        vfsStream::create([
69
            'config.json' => <<<JSON
70
{
71
    "scan-files": ["src/ComposerRequireChecker/Cli/CheckCommand.php"]
72
}
73
JSON
74
            ,
75
        ]);
76
77
        $this->commandTester->execute([
78
            // that's our own composer.json
79
            'composer-json' => dirname(__DIR__, 3) . '/composer.json',
80
            '--config-file' => $root->getChild('config.json')->url(),
81
        ]);
82
83
        $this->assertRegExp('/There were no unknown symbols found./', $this->commandTester->getDisplay());
84
    }
85
86
    public function testSourceFileThatUsesDevDependency(): void
87
    {
88
        $root = vfsStream::setup();
89
        vfsStream::create(['config.json' => '{"scan-files":["test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php"]}']);
90
91
        $exitCode = $this->commandTester->execute([
92
            // that's our own composer.json
93
            'composer-json' => dirname(__DIR__, 3) . '/composer.json',
94
            '--config-file' => $root->getChild('config.json')->url(),
95
        ]);
96
97
        $this->assertNotEquals(0, $exitCode);
98
        $this->assertRegExp('/The following unknown symbols were found.*PHPUnit\\\\Framework\\\\TestCase/s', $this->commandTester->getDisplay());
99
    }
100
}
101