Permalink
Browse files

test error code throws exception

  • Loading branch information...
1 parent 3e1a5d8 commit 9c51484707ac0c108ebf68a39bdf1079e7de8c91 @daaku daaku committed Jul 17, 2012
Showing with 24 additions and 0 deletions.
  1. +4 −0 src/base_facebook.php
  2. +20 −0 tests/tests.php
View
4 src/base_facebook.php
@@ -752,7 +752,9 @@ protected function _restserver($params) {
// results are returned, errors are thrown
if (is_array($result) && isset($result['error_code'])) {
$this->throwAPIException($result);
+ // @codeCoverageIgnoreStart
}
+ // @codeCoverageIgnoreEnd
$method = strtolower($params['method']);
if ($method === 'auth.expiresession' ||
@@ -809,7 +811,9 @@ protected function _graph($path, $method = 'GET', $params = array()) {
// results are returned, errors are thrown
if (is_array($result) && isset($result['error'])) {
$this->throwAPIException($result);
+ // @codeCoverageIgnoreStart
}
+ // @codeCoverageIgnoreEnd
return $result;
}
View
20 tests/tests.php
@@ -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() {
return md5(uniqid(mt_rand(), true));
}

0 comments on commit 9c51484

Please sign in to comment.