These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\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\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([]); |
||
0 ignored issues
–
show
|
|||
38 | $kernelMock->shouldReceive('getContainer->has')->andReturn(false); |
||
39 | $kernelMock->shouldReceive('getContainer->hasParameter')->andReturn(false); |
||
40 | $kernelMock->shouldReceive('getContainer->get') |
||
41 | ->with('event_dispatcher') |
||
42 | ->andReturn(new EventDispatcher()); |
||
43 | |||
44 | $kernelMock->shouldReceive('getContainer->get')->andReturn(false); |
||
45 | |||
46 | $this->feature = new Application($kernelMock); |
||
47 | $this->feature->setAutoExit(false); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @covers ::getCommandName |
||
52 | */ |
||
53 | public function testWhetherTheNameOfTheCommandCanBeRetrieved() |
||
54 | { |
||
55 | $_SERVER['argv'] = ['binary', 'my:command']; |
||
56 | $this->feature->add((new Command('my:command'))->setCode(function () { |
||
57 | return 1; |
||
58 | })); |
||
59 | $this->feature->add((new Command('project:run'))->setCode(function () { |
||
60 | return 2; |
||
61 | })); |
||
62 | |||
63 | $this->assertSame(1, $this->feature->run(new StringInput('my:command -q'))); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @covers ::getCommandName |
||
68 | */ |
||
69 | public function testWhetherTheRunCommandIsUsedWhenNoCommandNameIsGiven() |
||
70 | { |
||
71 | $_SERVER['argv'] = ['binary', 'something else']; |
||
72 | $this->feature->add((new Command('MyCommand'))->setCode(function () { |
||
73 | return 1; |
||
74 | })); |
||
75 | $this->feature->add((new Command('project:run'))->setCode(function () { |
||
76 | return 2; |
||
77 | })); |
||
78 | |||
79 | $this->assertSame(2, $this->feature->run(new StringInput('-q'))); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @covers ::getDefaultInputDefinition |
||
84 | */ |
||
85 | public function testWhetherTheConfigurationAndLogIsADefaultInput() |
||
86 | { |
||
87 | $definition = $this->feature->getDefinition(); |
||
88 | |||
89 | $this->assertTrue($definition->hasOption('config')); |
||
90 | $this->assertTrue($definition->hasOption('log')); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @covers ::getLongVersion |
||
95 | */ |
||
96 | public function testGetLongVersion(): void |
||
97 | { |
||
98 | self::assertRegExp( |
||
99 | '~phpDocumentor <info>v(\d).(\d).(\d|x)?-(.*)</info>~', |
||
100 | $this->feature->getLongVersion() |
||
101 | ); |
||
102 | } |
||
103 | } |
||
104 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: