Completed
Push — master ( 0d9cfe...073f2f )
by Joachim
12:30
created

TerminalManagerTest::testFindTerminalByTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
namespace Tests\Loevgaard\DandomainAltapayBundle\Manager;
3
4
use Loevgaard\DandomainAltapayBundle\Manager\TerminalManager;
5
use PHPUnit\Framework\TestCase;
6
7
class TerminalManagerTest extends TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject|TerminalManager
11
     */
12
    protected $manager;
13
14
    protected function setUp()
15
    {
16
        $this->manager = $this->getMockBuilder('Loevgaard\DandomainAltapayBundle\Manager\TerminalManager')
17
            ->disableOriginalConstructor()
18
            ->setMethods(['findTerminalByTitle'])
19
            ->getMock();
20
    }
21
22
    public function testFindTerminalByTitle()
23
    {
24
        $terminal = $this->getMockForAbstractClass('Loevgaard\DandomainAltapayBundle\Entity\Terminal');
25
26
        $this->manager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Loevgaard\DandomainAltap...Manager\TerminalManager.

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...
27
            ->method('findTerminalByTitle')
28
            ->with($this->equalTo('terminal'))
29
            ->willReturn($terminal)
30
        ;
31
        $this->manager->findTerminalByTitle('terminal');
0 ignored issues
show
Bug introduced by
The method findTerminalByTitle does only exist in Loevgaard\DandomainAltap...Manager\TerminalManager, but not in PHPUnit_Framework_MockObject_MockObject.

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...
32
    }
33
}