Skip to content

Commit 7f3ee11

Browse files
BenjaminBenjamin
Benjamin
authored and
Benjamin
committed
Mocked test for a bad api response
1 parent 7fd04bd commit 7f3ee11

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/Parse/ParseClientTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,36 @@ public function testStreamCAFile()
503503

504504
}
505505

506+
/**
507+
* @group bad-api-response
508+
*/
509+
public function testBadApiResponse()
510+
{
511+
$this->setExpectedException(ParseException::class,
512+
'Bad Request. Could not decode Response: (4) Syntax error');
513+
514+
$httpClient = ParseClient::getHttpClient();
515+
516+
// create a mock of the current http client
517+
$stubClient = $this->createMock(get_class($httpClient));
518+
519+
// stub the response type to return
520+
// something we will try to work with
521+
$stubClient
522+
->method('getResponseContentType')
523+
->willReturn('application/octet-stream');
524+
525+
$stubClient
526+
->method('send')
527+
->willReturn('This is not valid json!');
528+
529+
// replace the client with our stub
530+
ParseClient::setHttpClient($stubClient);
531+
532+
// attempt to save, which should not fire our given code
533+
$obj = new ParseObject('TestingClass');
534+
$obj->save();
535+
536+
}
537+
506538
}

0 commit comments

Comments
 (0)