Completed
Push — develop ( 8eb671...133594 )
by Mike
19:30 queued 09:24
created

Transformer/Router/ForFileProxyTest.php (2 issues)

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
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Transformer\Router;
13
14
use Mockery as m;
15
16
class ForFileProxyTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
17
{
18
    /** @var Rule|m\MockInterface */
19
    private $ruleMock;
20
21
    /** @var ForFileProxy */
22
    private $fixture;
23
24
    /**
25
     * Initializes the fixture with mocked dependencies.
26
     */
27
    protected function setUp()
28
    {
29
        $this->ruleMock = m::mock('phpDocumentor\Transformer\Router\Rule');
30
        $this->fixture = new ForFileProxy($this->ruleMock);
31
    }
32
33
    /**
34
     * @covers phpDocumentor\Transformer\Router\ForFileProxy::__construct
35
     */
36
    public function testIfDependenciesAreRegisteredOnInitialization()
37
    {
38
        $this->assertAttributeSame($this->ruleMock, 'rule', $this->fixture);
39
    }
40
41
    /**
42
     * @covers phpDocumentor\Transformer\Router\ForFileProxy::generate
43
     */
44
    public function testIfDirectorySeparatorsAreTranslated()
45
    {
46
        // Arrange
47
        $this->ruleMock->shouldReceive('generate')->with('test')->andReturn('/usr/bin/php');
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Transformer\Router\Rule.

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...
48
49
        // Act
50
        $result = $this->fixture->generate('test', '\\');
51
52
        // Assert
53
        $this->assertSame('\\usr\\bin\\php', $result);
54
    }
55
56
    /**
57
     * @covers phpDocumentor\Transformer\Router\ForFileProxy::generate
58
     */
59
    public function testIfNullIsReturnedIfNodeDoesNotMatch()
60
    {
61
        // Arrange
62
        $this->ruleMock->shouldReceive('generate')->with('test')->andReturn(false);
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Transformer\Router\Rule.

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...
63
64
        // Act
65
        $result = $this->fixture->generate('test', '\\');
66
67
        // Assert
68
        $this->assertFalse($result);
69
    }
70
}
71