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() |
|
|
|
|
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 |
|
|
|
|
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() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$terminal = $this->getTerminal(); |
55
|
|
|
|
56
|
|
|
$this->objectRepository |
|
|
|
|
57
|
|
|
->expects($this->any()) |
58
|
|
|
->method('findOneBy') |
59
|
|
|
->with(['title' => 'terminal']) |
60
|
|
|
->willReturn($terminal) |
61
|
|
|
; |
62
|
|
|
|
63
|
|
|
$res = $this->manager->findTerminalByTitle('terminal'); |
|
|
|
|
64
|
|
|
$this->assertInstanceOf(TerminalInterface::class, $res); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function testFindTerminalBySlug() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$terminal = $this->getTerminal(); |
70
|
|
|
|
71
|
|
|
$this->objectRepository |
|
|
|
|
72
|
|
|
->expects($this->any()) |
73
|
|
|
->method('findOneBy') |
74
|
|
|
->with(['slug' => 'terminal']) |
75
|
|
|
->willReturn($terminal) |
76
|
|
|
; |
77
|
|
|
|
78
|
|
|
$res = $this->manager->findTerminalBySlug('terminal'); |
|
|
|
|
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
|
|
|
|
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.