Completed
Push — develop ( 8fda15...dbbcf5 )
by Jaap
14s
created

Console/Command/Project/ParseCommandTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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
 *  @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 \Mockery as m;
16
use League\Pipeline\PipelineInterface;
17
use Mockery\Adapter\Phpunit\MockeryTestCase;
18
use phpDocumentor\Descriptor\ProjectDescriptor;
19
use phpDocumentor\Descriptor\ProjectDescriptorBuilder;
20
use phpDocumentor\Parser\Parser;
21
use Symfony\Component\Console\Input\ArrayInput;
22
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
23
use Zend\Cache\Storage\Adapter\Memory;
24
use Zend\I18n\Translator\Translator;
25
26
/**
27
 * @coversDefaultClass phpDocumentor\Application\Console\Command\Project\ParseCommand
28
 * @covers ::<protected>
29
 */
30
class ParseCommandTest extends MockeryTestCase
31
{
32
    /**
33
     * Tests the processing of target directory when non is provided.
34
     * @covers ::execute
35
     */
36
    public function testDefaultTargetDirCreation()
37
    {
38
        $this->markTestIncomplete('Needs to be updated, to new command');
39
        $input = new ArrayInput([]);
40
        $output = new DummyOutput();
41
42
        $cache = m::mock(Memory::class);
43
        $cache->shouldReceive('getOptions->setCacheDir')->with(m::type('string'));
44
        $cache->shouldReceive('getOptions->getCacheDir')->andReturn(sys_get_temp_dir());
0 ignored issues
show
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
45
        $cache->shouldReceive('getOptions->getReadable')->andReturn(true);
46
        $cache->shouldReceive('getOptions->getWritable')->andReturn(true);
47
        $cache->shouldReceive('getOptions->getKeyPattern')->andReturn('/.+/');
48
        $cache->shouldReceive('getOptions->getNamespace')->andReturn('PhpDoc\\Cache');
49
        $cache->shouldDeferMissing();
50
51
        $translator = m::mock(Translator::class);
52
        $translator->shouldReceive('translate')
53
            ->zeroOrMoreTimes();
54
55
        $parser = m::mock(Parser::class);
56
        $parser->shouldReceive(
57
            'setForced',
58
            'setEncoding',
59
            'setMarkers',
60
            'setIgnoredTags',
61
            'setValidate',
62
            'setDefaultPackageName',
63
            'setPath',
64
            'parse'
65
        );
66
67
        $projectDescriptorBuilder = m::mock(ProjectDescriptorBuilder::class);
68
        $projectDescriptorBuilder->shouldReceive('createProjectDescriptor', 'getProjectDescriptor')
69
            ->andReturn(new ProjectDescriptor('test'));
70
71
        $command = new ParseCommand(
72
            m::mock(PipelineInterface::class),
73
            m::mock(\phpDocumentor\Translator\Translator::class)
74
        );
75
76
        $command->run($input, $output);
77
    }
78
}
79