Completed
Push — master ( 7c1eaa...80d841 )
by Joachim
15:53
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
3
namespace Loevgaard\DandomainAltapayBundle\Tests\Manager;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Doctrine\Common\Persistence\ObjectRepository;
8
use Loevgaard\DandomainAltapayBundle\Entity\TerminalInterface;
9
use Loevgaard\DandomainAltapayBundle\Manager\TerminalManager;
10
use PHPUnit\Framework\TestCase;
11
12
class TerminalManagerTest extends TestCase
13
{
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject|TerminalManager
16
     */
17
    protected $manager;
18
19
    /**
20
     * @var \PHPUnit_Framework_MockObject_MockObject|ObjectRepository
21
     */
22
    protected $objectRepository;
23
24 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $objectManager = $this->getMockBuilder(ObjectManager::class)
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
30
        /** @var ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject $managerRegistry */
31
        $managerRegistry = $this->getMockBuilder(ManagerRegistry::class)
32
            ->disableOriginalConstructor()
33
            ->getMock();
34
35
        $managerRegistry
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ManagerRegistry.

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...
36
            ->expects($this->any())
37
            ->method('getManagerForClass')
38
            ->willReturn($objectManager);
39
40
        $this->objectRepository = $this->getMockBuilder(ObjectRepository::class)
41
            ->disableOriginalConstructor()
42
            ->getMock();
43
44
        $objectManager
45
            ->expects($this->any())
46
            ->method('getRepository')
47
            ->willReturn($this->objectRepository);
48
49
        $this->manager = new TerminalManager($managerRegistry, 'Loevgaard\DandomainAltapayBundle\Entity\Terminal');
50
    }
51
52 View Code Duplication
    public function testFindTerminalByTitle()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $terminal = $this->getTerminal();
55
56
        $this->objectRepository
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectRepository.

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...
57
            ->expects($this->any())
58
            ->method('findOneBy')
59
            ->with(['title' => 'terminal'])
60
            ->willReturn($terminal)
61
        ;
62
63
        $res = $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...
64
        $this->assertInstanceOf(TerminalInterface::class, $res);
65
    }
66
67 View Code Duplication
    public function testFindTerminalBySlug()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $terminal = $this->getTerminal();
70
71
        $this->objectRepository
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectRepository.

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...
72
            ->expects($this->any())
73
            ->method('findOneBy')
74
            ->with(['slug' => 'terminal'])
75
            ->willReturn($terminal)
76
        ;
77
78
        $res = $this->manager->findTerminalBySlug('terminal');
0 ignored issues
show
Bug introduced by
The method findTerminalBySlug 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...
79
        $this->assertInstanceOf(TerminalInterface::class, $res);
80
    }
81
82
    /**
83
     * @return TerminalInterface|\PHPUnit_Framework_MockObject_MockObject
84
     */
85
    protected function getTerminal()
86
    {
87
        return $this->getMockForAbstractClass('Loevgaard\DandomainAltapayBundle\Entity\Terminal');
88
    }
89
}
90