Skip to content

Commit 3ac65e1

Browse files
committed
fix Doctrine StatementRepository tests
1 parent 6f52499 commit 3ac65e1

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

Tests/Unit/Repository/StatementRepositoryTest.php

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ public function testSave()
7474
->mappedStatementRepository
7575
->expects($this->once())
7676
->method('storeMappedStatement')
77-
->with($this->equalTo(MappedStatement::createFromModel($statement)), true);
77+
->with(
78+
$this->callback(function (MappedStatement $mappedStatement) use ($statement) {
79+
return $this->assertMappedStatement(
80+
MappedStatement::createFromModel($statement),
81+
$mappedStatement
82+
);
83+
}),
84+
true
85+
);
7886

7987
$this->statementRepository->storeStatement($statement);
8088
}
@@ -86,7 +94,15 @@ public function testSaveWithoutFlush()
8694
->mappedStatementRepository
8795
->expects($this->once())
8896
->method('storeMappedStatement')
89-
->with($this->equalTo(MappedStatement::createFromModel($statement)), false);
97+
->with(
98+
$this->callback(function (MappedStatement $mappedStatement) use ($statement) {
99+
return $this->assertMappedStatement(
100+
MappedStatement::createFromModel($statement),
101+
$mappedStatement
102+
);
103+
}),
104+
false
105+
);
90106

91107
$this->statementRepository->storeStatement($statement, false);
92108
}
@@ -98,4 +114,57 @@ protected function createMappedStatementRepositoryMock()
98114
{
99115
return $this->getMock('\Xabbuh\XApi\Storage\Doctrine\Repository\MappedStatementRepository');
100116
}
117+
118+
private function assertMappedStatement(MappedStatement $expected, MappedStatement $actual)
119+
{
120+
if ($expected->id !== $actual->id) {
121+
return false;
122+
}
123+
124+
if (!$expected->actor->equals($actual->actor)) {
125+
return false;
126+
}
127+
128+
if (!$expected->verb->equals($actual->verb)) {
129+
return false;
130+
}
131+
132+
if (!$expected->object->equals($actual->object)) {
133+
return false;
134+
}
135+
136+
if (null === $expected->result && null !== $actual->result) {
137+
return false;
138+
}
139+
140+
if (null !== $expected->result && null === $actual->result) {
141+
return false;
142+
}
143+
144+
if (null !== $expected->result && !$expected->result->equals($actual->result)) {
145+
return false;
146+
}
147+
148+
if (null === $expected->authority && null !== $actual->authority) {
149+
return false;
150+
}
151+
152+
if (null !== $expected->authority && null === $actual->authority) {
153+
return false;
154+
}
155+
156+
if (null !== $expected->authority && !$expected->authority->equals($actual->authority)) {
157+
return false;
158+
}
159+
160+
if ($expected->created != $actual->created) {
161+
return false;
162+
}
163+
164+
if (null === $actual->stored) {
165+
return false;
166+
}
167+
168+
return true;
169+
}
101170
}

0 commit comments

Comments
 (0)