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 Rhumsaa\Uuid\Uuid; |
15
|
|
|
use Xabbuh\XApi\DataFixtures\StatementFixtures; |
16
|
|
|
use Xabbuh\XApi\DataFixtures\VerbFixtures; |
17
|
|
|
use Xabbuh\XApi\Model\StatementId; |
18
|
|
|
use Xabbuh\XApi\Model\StatementsFilter; |
19
|
|
|
use XApi\Repository\Doctrine\Mapping\Statement as MappedStatement; |
20
|
|
|
use XApi\Repository\Doctrine\Repository\StatementRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Christian Flothmann <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class StatementRepositoryTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|\XApi\Repository\Doctrine\Repository\Mapping\StatementRepository |
29
|
|
|
*/ |
30
|
|
|
private $mappedStatementRepository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var StatementRepository |
34
|
|
|
*/ |
35
|
|
|
private $statementRepository; |
36
|
|
|
|
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->mappedStatementRepository = $this->createMappedStatementRepositoryMock(); |
40
|
|
|
$this->statementRepository = new StatementRepository($this->mappedStatementRepository); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testFindStatementById() |
44
|
|
|
{ |
45
|
|
|
$statementId = StatementId::fromUuid(Uuid::uuid4()); |
46
|
|
|
$this |
|
|
|
|
47
|
|
|
->mappedStatementRepository |
48
|
|
|
->expects($this->once()) |
49
|
|
|
->method('findStatement') |
50
|
|
|
->with(array('id' => $statementId->getValue())) |
51
|
|
|
->will($this->returnValue(MappedStatement::fromModel(StatementFixtures::getMinimalStatement()))); |
52
|
|
|
|
53
|
|
|
$this->statementRepository->findStatementById($statementId); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testFindStatementsByCriteria() |
57
|
|
|
{ |
58
|
|
|
$verb = VerbFixtures::getTypicalVerb(); |
59
|
|
|
|
60
|
|
|
$this |
|
|
|
|
61
|
|
|
->mappedStatementRepository |
62
|
|
|
->expects($this->once()) |
63
|
|
|
->method('findStatements') |
64
|
|
|
->with($this->equalTo(array('verb' => $verb->getId()->getValue()))) |
65
|
|
|
->will($this->returnValue(array())); |
66
|
|
|
|
67
|
|
|
$filter = new StatementsFilter(); |
68
|
|
|
$filter->byVerb($verb); |
69
|
|
|
$this->statementRepository->findStatementsBy($filter); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function testSave() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$statement = StatementFixtures::getMinimalStatement(); |
75
|
|
|
$this |
|
|
|
|
76
|
|
|
->mappedStatementRepository |
77
|
|
|
->expects($this->once()) |
78
|
|
|
->method('storeStatement') |
79
|
|
|
->with( |
80
|
|
|
$this->callback(function (MappedStatement $mappedStatement) use ($statement) { |
81
|
|
|
$expected = MappedStatement::fromModel($statement); |
82
|
|
|
$actual = clone $mappedStatement; |
83
|
|
|
$actual->stored = null; |
84
|
|
|
|
85
|
|
|
return $expected == $actual; |
86
|
|
|
}), |
87
|
|
|
true |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$this->statementRepository->storeStatement($statement); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
public function testSaveWithoutFlush() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$statement = StatementFixtures::getMinimalStatement(); |
96
|
|
|
$this |
|
|
|
|
97
|
|
|
->mappedStatementRepository |
98
|
|
|
->expects($this->once()) |
99
|
|
|
->method('storeStatement') |
100
|
|
|
->with( |
101
|
|
|
$this->callback(function (MappedStatement $mappedStatement) use ($statement) { |
102
|
|
|
$expected = MappedStatement::fromModel($statement); |
103
|
|
|
$actual = clone $mappedStatement; |
104
|
|
|
$actual->stored = null; |
105
|
|
|
|
106
|
|
|
return $expected == $actual; |
107
|
|
|
}), |
108
|
|
|
false |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$this->statementRepository->storeStatement($statement, false); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\XApi\Repository\Doctrine\Repository\Mapping\StatementRepository |
116
|
|
|
*/ |
117
|
|
|
protected function createMappedStatementRepositoryMock() |
118
|
|
|
{ |
119
|
|
|
return $this->getMock('\XApi\Repository\Doctrine\Repository\Mapping\StatementRepository'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.