@@ -49,10 +49,10 @@ public function testFetchingNonExistingStatementThrowsException()
4949
5050 /**
5151 * @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
52- * @dataProvider getStatementsWithoutId
5352 */
54- public function testFetchingStatementAsVoidedStatementThrowsException (Statement $ statement )
53+ public function testFetchingStatementAsVoidedStatementThrowsException ()
5554 {
55+ $ statement = StatementFixtures::getTypicalStatement ()->withId (null );
5656 $ statementId = $ this ->statementRepository ->storeStatement ($ statement );
5757
5858 $ this ->statementRepository ->findVoidedStatementById ($ statementId );
@@ -86,9 +86,14 @@ public function testUuidIsNotGeneratedForNewStatementIfPresent(Statement $statem
8686 public function testCreatedStatementCanBeRetrievedByOriginalId (Statement $ statement )
8787 {
8888 $ this ->statementRepository ->storeStatement ($ statement );
89- $ fetchedStatement = $ this ->statementRepository ->findStatementById ($ statement ->getId ());
9089
91- $ this ->assertStatementEquals ($ statement , $ fetchedStatement );
90+ if ($ statement ->getVerb ()->isVoidVerb ()) {
91+ $ fetchedStatement = $ this ->statementRepository ->findVoidedStatementById ($ statement ->getId ());
92+ } else {
93+ $ fetchedStatement = $ this ->statementRepository ->findStatementById ($ statement ->getId ());
94+ }
95+
96+ $ this ->assertTrue ($ statement ->equals ($ fetchedStatement ));
9297 }
9398
9499 /**
@@ -98,20 +103,45 @@ public function testCreatedStatementCanBeRetrievedByGeneratedId(Statement $state
98103 {
99104 $ statement =$ statement ->withId (null );
100105 $ statementId = $ this ->statementRepository ->storeStatement ($ statement );
101- $ fetchedStatement = $ this ->statementRepository ->findStatementById ($ statementId );
106+
107+ if ($ statement ->getVerb ()->isVoidVerb ()) {
108+ $ fetchedStatement = $ this ->statementRepository ->findVoidedStatementById ($ statementId );
109+ } else {
110+ $ fetchedStatement = $ this ->statementRepository ->findStatementById ($ statementId );
111+ }
102112
103113 $ this ->assertNull ($ statement ->getId ());
104- $ this ->assertStatementEquals ($ statement, $ fetchedStatement, false );
114+ $ this ->assertTrue ($ statement-> equals ( $ fetchedStatement-> withId ( null )) );
105115 }
106116
107117 public function getStatementsWithId ()
108118 {
109- return $ this ->getStatements (StatementFixtures::DEFAULT_STATEMENT_ID );
119+ $ fixtures = array ();
120+
121+ foreach (get_class_methods ('Xabbuh\XApi\DataFixtures\StatementFixtures ' ) as $ method ) {
122+ $ statement = call_user_func (array ('Xabbuh\XApi\DataFixtures\StatementFixtures ' , $ method ));
123+
124+ if ($ statement instanceof Statement) {
125+ $ fixtures [$ method ] = array ($ statement ->withId (StatementId::fromString (StatementFixtures::DEFAULT_STATEMENT_ID )));
126+ }
127+ }
128+
129+ return $ fixtures ;
110130 }
111131
112132 public function getStatementsWithoutId ()
113133 {
114- return $ this ->getStatements (null );
134+ $ fixtures = array ();
135+
136+ foreach (get_class_methods ('Xabbuh\XApi\DataFixtures\StatementFixtures ' ) as $ method ) {
137+ $ statement = call_user_func (array ('Xabbuh\XApi\DataFixtures\StatementFixtures ' , $ method ));
138+
139+ if ($ statement instanceof Statement) {
140+ $ fixtures [$ method ] = array ($ statement ->withId (null ));
141+ }
142+ }
143+
144+ return $ fixtures ;
115145 }
116146
117147 /**
@@ -156,7 +186,7 @@ public function testCreatedVoidStatementCanBeRetrievedByOriginalId()
156186 $ this ->statementRepository ->storeStatement ($ statement );
157187 $ fetchedStatement = $ this ->statementRepository ->findVoidedStatementById ($ statement ->getId ());
158188
159- $ this ->assertStatementEquals ($ statement, $ fetchedStatement );
189+ $ this ->assertTrue ($ statement-> equals ( $ fetchedStatement) );
160190 }
161191
162192 public function testCreatedVoidStatementCanBeRetrievedByGeneratedId ()
@@ -166,46 +196,10 @@ public function testCreatedVoidStatementCanBeRetrievedByGeneratedId()
166196 $ fetchedStatement = $ this ->statementRepository ->findVoidedStatementById ($ statementId );
167197
168198 $ this ->assertNull ($ statement ->getId ());
169- $ this ->assertStatementEquals ($ statement, $ fetchedStatement, false );
199+ $ this ->assertTrue ($ statement-> equals ( $ fetchedStatement-> withId ( null )) );
170200 }
171201
172202 abstract protected function createStatementRepository ();
173203
174204 abstract protected function cleanDatabase ();
175-
176- private function getStatements ($ id )
177- {
178- return array (
179- 'minimal-statement ' => array (StatementFixtures::getMinimalStatement ($ id )),
180- 'statement-with-group-actor ' => array (StatementFixtures::getStatementWithGroupActor ($ id )),
181- 'statement-with-group-actor-without-members ' => array (StatementFixtures::getStatementWithGroupActorWithoutMembers ($ id )),
182- 'object-is-statement-reference ' => array (StatementFixtures::getStatementWithStatementRef ($ id )),
183- 'statement-with-result ' => array (StatementFixtures::getStatementWithResult ($ id )),
184- 'statement-with-agent-authority ' => array (StatementFixtures::getStatementWithAgentAuthority ($ id )),
185- 'statement-with-group-authority ' => array (StatementFixtures::getStatementWithGroupAuthority ($ id )),
186- );
187- }
188-
189- private function assertStatementEquals (Statement $ expected , Statement $ actual , $ validateId = true )
190- {
191- if ($ validateId ) {
192- $ this ->assertTrue ($ expected ->getId ()->equals ($ actual ->getId ()));
193- }
194-
195- $ this ->assertTrue ($ actual ->getActor ()->equals ($ expected ->getActor ()));
196- $ this ->assertTrue ($ actual ->getVerb ()->equals ($ expected ->getVerb ()));
197- $ this ->assertTrue ($ actual ->getObject ()->equals ($ expected ->getObject ()));
198-
199- if (null === $ expected ->getResult ()) {
200- $ this ->assertNull ($ actual ->getResult ());
201- } else {
202- $ this ->assertTrue ($ actual ->getResult ()->equals ($ expected ->getResult ()));
203- }
204-
205- if (null === $ expected ->getAuthority ()) {
206- $ this ->assertNull ($ actual ->getAuthority ());
207- } else {
208- $ this ->assertTrue ($ actual ->getAuthority ()->equals ($ expected ->getAuthority ()));
209- }
210- }
211205}
0 commit comments