Completed
Push — develop ( 4f9fdc...854bd0 )
by Mike
07:24
created

testWhetherTheRunCommandIsUsedWhenNoCommandNameIsGiven()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author    Mike van Riel <[email protected]>
9
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
10
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
11
 * @link      http://phpdoc.org
12
 */
13
14
namespace phpDocumentor\Application\Console;
15
16
use Mockery\Adapter\Phpunit\MockeryTestCase;
17
use Mockery as m;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\StringInput;
20
use Symfony\Component\EventDispatcher\EventDispatcher;
21
use Symfony\Component\HttpKernel\KernelInterface;
22
23
/**
24
 * @coversDefaultClass \phpDocumentor\Application\Console\Application
25
 * @covers ::__construct
26
 * @covers ::<private>
27
 */
28
class ApplicationTest extends MockeryTestCase
29
{
30
    /** @var Application */
31
    private $feature;
32
33
    public function setUp()
34
    {
35
        $kernelMock = m::mock(KernelInterface::class);
36
        $kernelMock->shouldIgnoreMissing();
37
        $kernelMock->shouldReceive('getBundles')->andReturn([]);
38
        $kernelMock->shouldReceive('getContainer->has')->andReturn(false);
39
        $kernelMock->shouldReceive('getContainer->hasParameter')->andReturn(false);
40
        $kernelMock->shouldReceive('getContainer->get')->with('event_dispatcher')->andReturn(new EventDispatcher());
41
        $kernelMock->shouldReceive('getContainer->get')->andReturn(false);
42
43
        $this->feature = new Application($kernelMock);
44
        $this->feature->setAutoExit(false);
45
    }
46
47
    /**
48
     * @covers ::getCommandName
49
     */
50
    public function testWhetherTheNameOfTheCommandCanBeRetrieved()
51
    {
52
        $_SERVER['argv'] = ['binary', 'my:command'];
53
        $this->feature->add((new Command('my:command'))->setCode(function() { return 1; }));
54
        $this->feature->add((new Command('project:run'))->setCode(function() { return 2; }));
55
56
        $this->assertSame(1, $this->feature->run(new StringInput('my:command -q')));
57
    }
58
59
    /**
60
     * @covers ::getCommandName
61
     */
62
    public function testWhetherTheRunCommandIsUsedWhenNoCommandNameIsGiven()
63
    {
64
        $_SERVER['argv'] = ['binary', 'something else'];
65
        $this->feature->add((new Command('MyCommand'))->setCode(function() { return 1; }));
66
        $this->feature->add((new Command('project:run'))->setCode(function() { return 2; }));
67
68
        $this->assertSame(2, $this->feature->run(new StringInput('-q')));
69
    }
70
71
    /**
72
     * @covers ::getDefaultInputDefinition
73
     */
74
    public function testWhetherTheConfigurationAndLogIsADefaultInput()
75
    {
76
        $definition = $this->feature->getDefinition();
77
78
        $this->assertTrue($definition->hasOption('config'));
79
        $this->assertTrue($definition->hasOption('log'));
80
    }
81
82
    /**
83
     * @covers ::getLongVersion
84
     */
85
    public function testGetLongVersion(): void
86
    {
87
        self::assertRegExp('~phpDocumentor <info>v(\d).(\d).(\d|x)?-(.*)</info>~', $this->feature->getLongVersion());
88
    }
89
}
90