Skip to content

Commit 105c937

Browse files
committed
compatibility with php-xapi/model 0.5.0
1 parent e92241b commit 105c937

File tree

6 files changed

+47
-46
lines changed

6 files changed

+47
-46
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ CHANGELOG
44
0.2.0
55
-----
66

7-
* made the client compatible with version 0.2 of the `php-xapi/model` package
7+
* made the client compatible with version 0.5 of the `php-xapi/model` package
8+
9+
* made the client compatible with version 0.3 of the `php-xapi/serializer` package
810

911
0.1.0
1012
-----

UPGRADE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UPGRADE
2+
=======
3+
4+
Upgrading from 0.1 to 0.2
5+
-------------------------
6+
7+
* Statement identifiers must be passed as `StatementId` objects instead of
8+
strings.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"php": ">=5.3.0",
1616
"guzzle/guzzle": "~3.7",
1717
"php-xapi/exception": "^0.1.0",
18-
"php-xapi/model": "^0.2.0",
19-
"php-xapi/serializer": "^0.2.0"
18+
"php-xapi/model": "^0.5.0@dev",
19+
"php-xapi/serializer": "^0.3.0@dev"
2020
},
2121
"require-dev": {
22-
"php-xapi/test-fixtures": "^0.2.0"
22+
"php-xapi/test-fixtures": "^0.5.0@dev"
2323
},
2424
"conflict": {
2525
"xabbuh/xapi-client": "*"
@@ -36,7 +36,7 @@
3636
},
3737
"extra": {
3838
"branch-alias": {
39-
"dev-master": "0.1.x-dev"
39+
"dev-master": "0.2.x-dev"
4040
}
4141
}
4242
}

src/Api/StatementsApiClient.php

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Xabbuh\XApi\Client\Api;
1313

1414
use Xabbuh\XApi\Client\Request\HandlerInterface;
15+
use Xabbuh\XApi\Model\StatementId;
1516
use Xabbuh\XApi\Serializer\ActorSerializerInterface;
1617
use Xabbuh\XApi\Serializer\StatementResultSerializerInterface;
1718
use Xabbuh\XApi\Serializer\StatementSerializerInterface;
@@ -71,7 +72,7 @@ public function storeStatement(Statement $statement)
7172
return $this->doStoreStatements(
7273
$statement,
7374
'put',
74-
array('statementId' => $statement->getId()),
75+
array('statementId' => $statement->getId()->getValue()),
7576
204
7677
);
7778
} else {
@@ -109,17 +110,17 @@ public function voidStatement(Statement $statement, Actor $actor)
109110
/**
110111
* {@inheritDoc}
111112
*/
112-
public function getStatement($statementId)
113+
public function getStatement(StatementId $statementId)
113114
{
114-
return $this->doGetStatements('statements', array('statementId' => $statementId));
115+
return $this->doGetStatements('statements', array('statementId' => $statementId->getValue()));
115116
}
116117

117118
/**
118119
* {@inheritDoc}
119120
*/
120-
public function getVoidedStatement($statementId)
121+
public function getVoidedStatement(StatementId $statementId)
121122
{
122-
return $this->doGetStatements('statements', array('voidedStatementId' => $statementId));
123+
return $this->doGetStatements('statements', array('voidedStatementId' => $statementId->getValue()));
123124
}
124125

125126
/**
@@ -179,35 +180,17 @@ private function doStoreStatements($statements, $method = 'post', $parameters =
179180
$createdStatements = array();
180181

181182
foreach ($statements as $index => $statement) {
182-
$createdStatements[] = new Statement(
183-
$statementIds[$index],
184-
$statement->getActor(),
185-
$statement->getVerb(),
186-
$statement->getObject(),
187-
$statement->getResult()
188-
);
183+
$createdStatements[] = $statement->withId(StatementId::fromString($statementIds[$index]));
189184
}
190185

191186
return $createdStatements;
192187
} else {
193188
/** @var Statement $statements */
194189

195190
if (200 === $validStatusCode) {
196-
return new Statement(
197-
$statementIds[0],
198-
$statements->getActor(),
199-
$statements->getVerb(),
200-
$statements->getObject(),
201-
$statements->getResult()
202-
);
191+
return $statements->withId(StatementId::fromString($statementIds[0]));
203192
} else {
204-
return new Statement(
205-
$statements->getId(),
206-
$statements->getActor(),
207-
$statements->getVerb(),
208-
$statements->getObject(),
209-
$statements->getResult()
210-
);
193+
return $statements;
211194
}
212195
}
213196
}

src/Api/StatementsApiClientInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Xabbuh\XApi\Common\Exception\XApiException;
1717
use Xabbuh\XApi\Model\Actor;
1818
use Xabbuh\XApi\Model\Statement;
19+
use Xabbuh\XApi\Model\StatementId;
1920
use Xabbuh\XApi\Model\StatementResult;
2021
use Xabbuh\XApi\Model\StatementsFilter;
2122

@@ -78,26 +79,26 @@ public function voidStatement(Statement $statement, Actor $actor);
7879
/**
7980
* Retrieves a single {@link Statement Statement}.
8081
*
81-
* @param string $statementId The Statement id
82+
* @param StatementId $statementId The Statement id
8283
*
8384
* @return Statement The Statement
8485
*
8586
* @throws NotFoundException if no statement with the given id could be found
8687
* @throws XApiException for all other xAPI related problems
8788
*/
88-
public function getStatement($statementId);
89+
public function getStatement(StatementId $statementId);
8990

9091
/**
9192
* Retrieves a voided {@link Statement Statement}.
9293
*
93-
* @param string $statementId The id of the voided Statement
94+
* @param StatementId $statementId The id of the voided Statement
9495
*
9596
* @return Statement The voided Statement
9697
*
9798
* @throws NotFoundException if no statement with the given id could be found
9899
* @throws XApiException for all other xAPI related problems
99100
*/
100-
public function getVoidedStatement($statementId);
101+
public function getVoidedStatement(StatementId $statementId);
101102

102103
/**
103104
* Retrieves a collection of {@link Statement Statements}.

tests/Api/StatementsApiClientTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Xabbuh\XApi\Model\Agent;
1717
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
1818
use Xabbuh\XApi\Model\Statement;
19+
use Xabbuh\XApi\Model\StatementId;
1920
use Xabbuh\XApi\Model\StatementReference;
2021
use Xabbuh\XApi\Model\StatementResult;
2122
use Xabbuh\XApi\Model\StatementsFilter;
@@ -94,7 +95,7 @@ public function testStoreStatementWithIdEnsureThatTheIdIsNotOverwritten()
9495
);
9596
$storedStatement = $this->client->storeStatement($statement);
9697

97-
$this->assertEquals($statementId, $storedStatement->getId());
98+
$this->assertEquals($statementId, $storedStatement->getId()->getValue());
9899
}
99100

100101
public function testStoreStatements()
@@ -119,8 +120,8 @@ public function testStoreStatements()
119120
$this->assertNotContains($statements[0], array($statement1, $statement2));
120121
$this->assertNotContains($statements[1], array($statement1, $statement2));
121122
$this->assertEquals($expectedStatements, $statements);
122-
$this->assertEquals($statementId1, $statements[0]->getId());
123-
$this->assertEquals($statementId2, $statements[1]->getId());
123+
$this->assertEquals($statementId1, $statements[0]->getId()->getValue());
124+
$this->assertEquals($statementId2, $statements[1]->getId()->getValue());
124125
}
125126

126127
/**
@@ -161,7 +162,7 @@ public function testVoidStatement()
161162
$voidedStatementId = '12345678-1234-5678-1234-567812345679';
162163
$voidingStatementId = '12345678-1234-5678-1234-567812345678';
163164
$agent = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
164-
$statementReference = new StatementReference($voidedStatementId);
165+
$statementReference = new StatementReference(StatementId::fromString($voidedStatementId));
165166
$voidingStatement = new Statement(null, $agent, Verb::createVoidVerb(), $statementReference);
166167
$voidedStatement = $this->createStatement($voidedStatementId);
167168
$this->validateStoreApiCall(
@@ -174,7 +175,7 @@ public function testVoidStatement()
174175
);
175176
$returnedVoidingStatement = $this->client->voidStatement($voidedStatement, $agent);
176177
$expectedVoidingStatement = new Statement(
177-
$voidingStatementId,
178+
StatementId::fromString($voidingStatementId),
178179
$agent,
179180
Verb::createVoidVerb(),
180181
$statementReference
@@ -196,7 +197,7 @@ public function testGetStatement()
196197
$statement
197198
);
198199

199-
$this->client->getStatement($statementId);
200+
$this->client->getStatement(StatementId::fromString($statementId));
200201
}
201202

202203
/**
@@ -214,7 +215,7 @@ public function testGetStatementWithNotExistingStatement()
214215
'There is no statement associated with this id'
215216
);
216217

217-
$this->client->getStatement($statementId);
218+
$this->client->getStatement(StatementId::fromString($statementId));
218219
}
219220

220221
public function testGetVoidedStatement()
@@ -230,7 +231,7 @@ public function testGetVoidedStatement()
230231
$statement
231232
);
232233

233-
$this->client->getVoidedStatement($statementId);
234+
$this->client->getVoidedStatement(StatementId::fromString($statementId));
234235
}
235236

236237
/**
@@ -248,7 +249,7 @@ public function testGetVoidedStatementWithNotExistingStatement()
248249
'There is no statement associated with this id'
249250
);
250251

251-
$this->client->getVoidedStatement($statementId);
252+
$this->client->getVoidedStatement(StatementId::fromString($statementId));
252253
}
253254

254255
public function testGetStatements()
@@ -274,7 +275,7 @@ public function testGetStatementsWithStatementsFilter()
274275
$this->validateRetrieveApiCall(
275276
'get',
276277
'statements',
277-
array('limit' => 10, 'ascending' => 'True'),
278+
array('limit' => 10, 'ascending' => 'true'),
278279
200,
279280
'StatementResult',
280281
$statementResult
@@ -351,7 +352,13 @@ public function testGetNextStatements()
351352
*/
352353
private function createStatement($id = null)
353354
{
354-
return StatementFixtures::getMinimalStatement($id);
355+
$statement = StatementFixtures::getMinimalStatement($id);
356+
357+
if (null === $id) {
358+
$statement = $statement->withId(null);
359+
}
360+
361+
return $statement;
355362
}
356363

357364
/**

0 commit comments

Comments
 (0)