|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\Terminal; |
|
6
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\TerminalRepository; |
|
7
|
|
|
use Loevgaard\DandomainAltapayBundle\Synchronizer\TerminalSynchronizer; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
10
|
|
|
|
|
11
|
|
|
class TerminalRepositoryTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testReturnNull() |
|
14
|
|
|
{ |
|
15
|
|
|
$terminalRepository = $this->getTerminalRepository(); |
|
16
|
|
|
|
|
17
|
|
|
$terminalRepository |
|
18
|
|
|
->method('findOneBy') |
|
19
|
|
|
->willReturn(null); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertSame(null, $terminalRepository->findTerminalBySlug('slug')); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
public function testFindTerminalByTitle() |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$terminalRepository = $this->getTerminalRepository(); |
|
27
|
|
|
|
|
28
|
|
|
$obj = new Terminal(); |
|
29
|
|
|
$terminalRepository |
|
30
|
|
|
->method('findOneBy') |
|
31
|
|
|
->willReturn($obj); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertSame($obj, $terminalRepository->findTerminalByTitle('title')); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
public function testFindTerminalByTitleWithFetch() |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$terminalRepository = $this->getTerminalRepository(); |
|
39
|
|
|
|
|
40
|
|
|
$obj = new Terminal(); |
|
41
|
|
|
$terminalRepository |
|
42
|
|
|
->method('findOneBy') |
|
43
|
|
|
->will($this->onConsecutiveCalls(null, $obj)); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertSame($obj, $terminalRepository->findTerminalByTitle('title', true)); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
View Code Duplication |
public function testFindTerminalBySlug() |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$terminalRepository = $this->getTerminalRepository(); |
|
51
|
|
|
|
|
52
|
|
|
$obj = new Terminal(); |
|
53
|
|
|
$terminalRepository |
|
54
|
|
|
->method('findOneBy') |
|
55
|
|
|
->willReturn($obj); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertSame($obj, $terminalRepository->findTerminalBySlug('slug')); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
View Code Duplication |
public function testFindTerminalBySlugWithFetch() |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
$terminalRepository = $this->getTerminalRepository(); |
|
63
|
|
|
|
|
64
|
|
|
$obj = new Terminal(); |
|
65
|
|
|
$terminalRepository |
|
66
|
|
|
->method('findOneBy') |
|
67
|
|
|
->will($this->onConsecutiveCalls(null, $obj)); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertSame($obj, $terminalRepository->findTerminalBySlug('slug', true)); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return TerminalRepository|\PHPUnit_Framework_MockObject_MockObject |
|
74
|
|
|
*/ |
|
75
|
|
|
private function getTerminalRepository() |
|
76
|
|
|
{ |
|
77
|
|
|
/** @var TerminalRepository|\PHPUnit_Framework_MockObject_MockObject $terminalRepository */ |
|
78
|
|
|
$terminalRepository = $this->getMockBuilder(TerminalRepository::class) |
|
79
|
|
|
->disableOriginalConstructor() |
|
80
|
|
|
->setMethods(['findOneBy']) |
|
81
|
|
|
->getMock(); |
|
82
|
|
|
|
|
83
|
|
|
$container = $this->getMockBuilder(ContainerInterface::class) |
|
84
|
|
|
->disableOriginalConstructor() |
|
85
|
|
|
->getMock(); |
|
86
|
|
|
|
|
87
|
|
|
$terminalSynchronizer = $this->getMockBuilder(TerminalSynchronizer::class) |
|
88
|
|
|
->disableOriginalConstructor() |
|
89
|
|
|
->getMock(); |
|
90
|
|
|
|
|
91
|
|
|
$terminalSynchronizer |
|
92
|
|
|
->method('syncAll') |
|
93
|
|
|
->willReturn(null); |
|
94
|
|
|
|
|
95
|
|
|
// the only get call we do is a call to retrieve the terminal synchronizer |
|
96
|
|
|
$container |
|
97
|
|
|
->method('get') |
|
98
|
|
|
->willReturn($terminalSynchronizer); |
|
99
|
|
|
|
|
100
|
|
|
$terminalRepository->setContainer($container); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return $terminalRepository; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: