Skip to content

Commit 0192ace

Browse files
authored
Merge pull request #69 from brianjmiller/issue62
Silence undefined warnings in `RemoteLRS.sendRequest`
2 parents 3eba26f + 52880e3 commit 0192ace

File tree

2 files changed

+48
-33
lines changed

2 files changed

+48
-33
lines changed

src/RemoteLRS.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ function ($errno, $errstr, $errfile, $errline, array $errcontext) {
131131
}
132132
);
133133

134+
$fp = null;
135+
$response = null;
136+
134137
try {
135138
$context = stream_context_create(array( 'http' => $http ));
136139
$fp = fopen($url, 'rb', false, $context);

tests/RemoteLRSTest.php

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,15 @@ public function testRetrieveStatement() {
205205
])
206206
]
207207
);
208-
if ($saveResponse->success) {
209-
$response = $lrs->retrieveStatement($saveResponse->content->getId());
210-
211-
$this->assertInstanceOf('TinCan\LRSResponse', $response);
212-
$this->assertTrue($response->success);
213-
$this->assertInstanceOf('TinCan\Statement', $response->content);
214-
}
215-
else {
216-
// TODO: skipped? throw?
208+
if (! $saveResponse->success) {
209+
$this->fail("save statement setup failed: " . $saveResponse->content);
217210
}
211+
212+
$response = $lrs->retrieveStatement($saveResponse->content->getId());
213+
214+
$this->assertInstanceOf('TinCan\LRSResponse', $response);
215+
$this->assertTrue($response->success);
216+
$this->assertInstanceOf('TinCan\Statement', $response->content);
218217
}
219218

220219
public function testRetrieveStatementWithAttachments() {
@@ -243,6 +242,9 @@ public function testRetrieveStatementWithAttachments() {
243242
]
244243
);
245244
$this->assertTrue($saveResponse->success, 'save succeeded');
245+
if (! $saveResponse->success) {
246+
$this->fail("save statement setup failed: " . $saveResponse->content);
247+
}
246248

247249
$response = $lrs->retrieveStatement($saveResponse->content->getId(), [ 'attachments' => true ]);
248250

@@ -269,6 +271,10 @@ public function testRetrieveVoidedStatement() {
269271
])
270272
]
271273
);
274+
if (! $saveResponse->success) {
275+
$this->fail("save statement setup failed: " . $saveResponse->content);
276+
}
277+
272278
$voidResponse = $lrs->saveStatement(
273279
[
274280
'actor' => [
@@ -280,6 +286,10 @@ public function testRetrieveVoidedStatement() {
280286
])
281287
]
282288
);
289+
if (! $voidResponse->success) {
290+
$this->fail("void statement setup failed: " . $voidResponse->content);
291+
}
292+
283293
$retrieveResponse = $lrs->retrieveVoidedStatement($saveResponse->content->getId());
284294

285295
$this->assertInstanceOf('TinCan\LRSResponse', $retrieveResponse);
@@ -308,41 +318,37 @@ public function testQueryStatementsWithAttachments() {
308318
public function testMoreStatements() {
309319
$lrs = new RemoteLRS(self::$endpoint, self::$version, self::$username, self::$password);
310320
$queryResponse = $lrs->queryStatements(['limit' => 1]);
321+
if (! $queryResponse->success) {
322+
$this->fail("query statements setup failed: " . $queryResponse->content);
323+
}
311324

312-
if ($queryResponse->success) {
313-
if (! $queryResponse->content->getMore()) {
314-
$this->markTestSkipped('No more property in StatementsResult (not enough statements in endpoint?)');
315-
}
325+
if (! $queryResponse->content->getMore()) {
326+
$this->markTestSkipped('No more property in StatementsResult (not enough statements in endpoint?)');
327+
}
316328

317-
$response = $lrs->moreStatements($queryResponse->content);
329+
$response = $lrs->moreStatements($queryResponse->content);
318330

319-
$this->assertInstanceOf('TinCan\LRSResponse', $response);
320-
$this->assertTrue($response->success, 'success');
321-
$this->assertInstanceOf('TinCan\StatementsResult', $response->content, 'content');
322-
}
323-
else {
324-
$this->markTestSkipped('Query to get "more" URL failed');
325-
}
331+
$this->assertInstanceOf('TinCan\LRSResponse', $response);
332+
$this->assertTrue($response->success, 'success');
333+
$this->assertInstanceOf('TinCan\StatementsResult', $response->content, 'content');
326334
}
327335

328336
public function testMoreStatementsWithAttachments() {
329337
$lrs = new RemoteLRS(self::$endpoint, self::$version, self::$username, self::$password);
330338
$queryResponse = $lrs->queryStatements(['limit' => 1, 'attachments' => true]);
339+
if (! $queryResponse->success) {
340+
$this->fail("query statements setup failed: " . $queryResponse->content);
341+
}
331342

332-
if ($queryResponse->success) {
333-
if (! $queryResponse->content->getMore()) {
334-
$this->markTestSkipped('No more property in StatementsResult (not enough statements in endpoint?)');
335-
}
343+
if (! $queryResponse->content->getMore()) {
344+
$this->markTestSkipped('No more property in StatementsResult (not enough statements in endpoint?)');
345+
}
336346

337-
$response = $lrs->moreStatements($queryResponse->content);
347+
$response = $lrs->moreStatements($queryResponse->content);
338348

339-
$this->assertInstanceOf('TinCan\LRSResponse', $response);
340-
$this->assertTrue($response->success, 'success');
341-
$this->assertInstanceOf('TinCan\StatementsResult', $response->content, 'content');
342-
}
343-
else {
344-
$this->markTestSkipped('Query to get "more" URL failed');
345-
}
349+
$this->assertInstanceOf('TinCan\LRSResponse', $response);
350+
$this->assertTrue($response->success, 'success');
351+
$this->assertInstanceOf('TinCan\StatementsResult', $response->content, 'content');
346352
}
347353

348354
public function testRetrieveStateIds() {
@@ -424,6 +430,9 @@ public function testRetrieveActivityProfile() {
424430
'contentType' => 'application/json',
425431
]
426432
);
433+
if (! $response->success) {
434+
$this->fail("save activity profile setup failed: " . $response->content);
435+
}
427436

428437
$response = $lrs->retrieveActivityProfile(
429438
new Activity(
@@ -486,6 +495,9 @@ public function testRetrieveActivity() {
486495
]
487496
);
488497
$response = $lrs->saveStatement($statement);
498+
if (! $response->success) {
499+
$this->fail("save statement setup failed: " . $response->content);
500+
}
489501

490502
$response = $lrs->retrieveActivity($testActivity->getId());
491503
$this->assertInstanceOf('TinCan\LRSResponse', $response);

0 commit comments

Comments
 (0)