Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
test error code throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
daaku committed Jul 17, 2012
1 parent 3e1a5d8 commit 9c51484
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/base_facebook.php
Expand Up @@ -752,7 +752,9 @@ protected function _restserver($params) {
// results are returned, errors are thrown // results are returned, errors are thrown
if (is_array($result) && isset($result['error_code'])) { if (is_array($result) && isset($result['error_code'])) {
$this->throwAPIException($result); $this->throwAPIException($result);
// @codeCoverageIgnoreStart
} }
// @codeCoverageIgnoreEnd


$method = strtolower($params['method']); $method = strtolower($params['method']);
if ($method === 'auth.expiresession' || if ($method === 'auth.expiresession' ||
Expand Down Expand Up @@ -809,7 +811,9 @@ protected function _graph($path, $method = 'GET', $params = array()) {
// results are returned, errors are thrown // results are returned, errors are thrown
if (is_array($result) && isset($result['error'])) { if (is_array($result) && isset($result['error'])) {
$this->throwAPIException($result); $this->throwAPIException($result);
// @codeCoverageIgnoreStart
} }
// @codeCoverageIgnoreEnd


return $result; return $result;
} }
Expand Down
20 changes: 20 additions & 0 deletions tests/tests.php
Expand Up @@ -1332,6 +1332,26 @@ public function testLowercaseAuthRevokeAuthDestroysSession() {
); );
} }


/**
* @expectedException FacebookAPIException
*/
public function testErrorCodeFromRestAPIThrowsException() {
$methods_to_stub = array(
'_oauthRequest',
);
$constructor_args = array(array(
'appId' => self::APP_ID,
'secret' => self::SECRET
));
$stub = $this->getMock(
'TransientFacebook', $methods_to_stub, $constructor_args);
$stub
->expects($this->once())
->method('_oauthRequest')
->will($this->returnValue('{"error_code": 500}'));
$stub->api(array('method' => 'foo'));
}

protected function generateMD5HashOfRandomValue() { protected function generateMD5HashOfRandomValue() {
return md5(uniqid(mt_rand(), true)); return md5(uniqid(mt_rand(), true));
} }
Expand Down

0 comments on commit 9c51484

Please sign in to comment.