Completed
Push — develop ( d73a05...7ce957 )
by Mike
07:24
created

Application/Stage/Parser/ConfigureCacheTest.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\Stage\Parser;
14
15
use \Mockery as m;
16
use Mockery\Adapter\Phpunit\MockeryTestCase;
17
use phpDocumentor\DomainModel\Path;
18
use Zend\Cache\Storage\StorageInterface;
19
20
class ConfigureCacheTest extends MockeryTestCase
21
{
22
    /**
23
     * @dataProvider cacheDirProvider
24
     * @throws \Exception
25
     */
26
    public function testInvokeWithCachePath($configuredPath, $expectedPath)
27
    {
28
        $configuration = [
29
            'phpdocumentor' => [
30
                'paths' => [
31
                    'cache' => $configuredPath,
32
                ],
33
            ],
34
        ];
35
36
        $cacheStorage = m::mock(StorageInterface::class);
37
        $cacheStorage->shouldReceive('getOptions->setCacheDir')->withArgs([$expectedPath])->once();
0 ignored issues
show
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
39
        $stage = new ConfigureCache($cacheStorage);
40
41
        self::assertSame($configuration, $stage($configuration));
42
    }
43
44
    public function cacheDirProvider()
45
    {
46
        return [
47
            [
48
                '/tmp/cache',
49
                '/tmp/cache',
50
            ],
51
            [
52
                'cache/relative',
53
                getcwd() . DIRECTORY_SEPARATOR . 'cache/relative',
54
            ],
55
            [
56
                new Path('/tmp/cache'),
57
                '/tmp/cache',
58
            ],
59
            [
60
                new Path('cache/relative'),
61
                getcwd() . DIRECTORY_SEPARATOR . 'cache/relative',
62
            ],
63
        ];
64
    }
65
}
66