Completed
Push — develop ( 3f782b...e47f52 )
by Mike
11:13 queued 05:45
created

testPipelineIsInvokedWithTheNecessaryOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 17
rs 9.7
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
 *  @copyright 2010-2018 Mike van Riel<[email protected]>
9
 *  @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 *  @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Application\Console\Command\Project;
14
15
use League\Pipeline\PipelineInterface;
16
use Mockery as m;
17
use Mockery\Adapter\Phpunit\MockeryTestCase;
18
use Symfony\Component\Console\Input\StringInput;
19
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
20
21
/**
22
 * @coversDefaultClass phpDocumentor\Application\Console\Command\Project\TransformCommand
23
 * @covers ::<protected>
24
 */
25
class TransformCommandTest extends MockeryTestCase
26
{
27
    /**
28
     * Tests the processing of target directory when non is provided.
29
     * @covers ::execute
30
     */
31
    public function testPipelineIsInvokedWithTheNecessaryOptions()
32
    {
33
        $input = new StringInput('-t abc');
34
        $output = new DummyOutput();
35
36
        $pipeline = m::mock(PipelineInterface::class);
37
        $pipeline
0 ignored issues
show
Bug introduced by
The method withArgs does only exist in Mockery\HigherOrderMessage, but not in Mockery\ExpectationInterface.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
38
            ->shouldReceive('__invoke')
39
            ->withArgs(function(array $options){
40
                return $options['target'] === 'abc';
41
            })
42
            ->once();
43
44
        $command = new TransformCommand($pipeline);
45
46
        $this->assertSame(0, $command->run($input, $output));
47
    }
48
}
49