1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace XApi\Repository\Doctrine\Tests\Unit\Repository; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\DataFixtures\StatementFixtures; |
15
|
|
|
use XApi\Repository\Api\Mapping\MappedStatement; |
16
|
|
|
use XApi\Repository\Doctrine\Repository\MappedStatementRepository; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Christian Flothmann <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
abstract class MappedStatementRepositoryTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
25
|
|
|
*/ |
26
|
|
|
private $objectManager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
30
|
|
|
*/ |
31
|
|
|
private $unitOfWork; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
35
|
|
|
*/ |
36
|
|
|
private $classMetadata; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var MappedStatementRepository |
40
|
|
|
*/ |
41
|
|
|
private $repository; |
42
|
|
|
|
43
|
|
|
protected function setUp() |
44
|
|
|
{ |
45
|
|
|
$this->objectManager = $this->createObjectManagerMock(); |
46
|
|
|
$this->unitOfWork = $this->createUnitOfWorkMock(); |
47
|
|
|
$this->classMetadata = $this->createClassMetadataMock(); |
48
|
|
|
$this->repository = $this->createMappedStatementRepository($this->objectManager, $this->unitOfWork, $this->classMetadata); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testStatementDocumentIsPersisted() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$this |
54
|
|
|
->objectManager |
55
|
|
|
->expects($this->once()) |
56
|
|
|
->method('persist') |
57
|
|
|
->with($this->isInstanceOf('\XApi\Repository\Api\Mapping\MappedStatement')) |
58
|
|
|
; |
59
|
|
|
|
60
|
|
|
$mappedStatement = MappedStatement::createFromModel(StatementFixtures::getMinimalStatement()); |
61
|
|
|
$this->repository->storeMappedStatement($mappedStatement, true); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testFlushIsCalledByDefault() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$this |
67
|
|
|
->objectManager |
68
|
|
|
->expects($this->once()) |
69
|
|
|
->method('flush') |
70
|
|
|
; |
71
|
|
|
|
72
|
|
|
$mappedStatement = MappedStatement::createFromModel(StatementFixtures::getMinimalStatement()); |
73
|
|
|
$this->repository->storeMappedStatement($mappedStatement); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function testCallToFlushCanBeSuppressed() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
$this |
79
|
|
|
->objectManager |
80
|
|
|
->expects($this->never()) |
81
|
|
|
->method('flush') |
82
|
|
|
; |
83
|
|
|
|
84
|
|
|
$mappedStatement = MappedStatement::createFromModel(StatementFixtures::getMinimalStatement()); |
85
|
|
|
$this->repository->storeMappedStatement($mappedStatement, false); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
abstract protected function getObjectManagerClass(); |
89
|
|
|
|
90
|
|
|
protected function createObjectManagerMock() |
91
|
|
|
{ |
92
|
|
|
return $this |
93
|
|
|
->getMockBuilder($this->getObjectManagerClass()) |
94
|
|
|
->disableOriginalConstructor() |
95
|
|
|
->getMock(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
abstract protected function getUnitOfWorkClass(); |
99
|
|
|
|
100
|
|
|
protected function createUnitOfWorkMock() |
101
|
|
|
{ |
102
|
|
|
return $this |
103
|
|
|
->getMockBuilder($this->getUnitOfWorkClass()) |
104
|
|
|
->disableOriginalConstructor() |
105
|
|
|
->getMock(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
abstract protected function getClassMetadataClass(); |
109
|
|
|
|
110
|
|
|
protected function createClassMetadataMock() |
111
|
|
|
{ |
112
|
|
|
return $this |
113
|
|
|
->getMockBuilder($this->getClassMetadataClass()) |
114
|
|
|
->disableOriginalConstructor() |
115
|
|
|
->getMock(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
abstract protected function createMappedStatementRepository($objectManager, $unitOfWork, $classMetadata); |
119
|
|
|
} |
120
|
|
|
|
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.