respondWith = 'FAIL_ON_START'; } public function failOnTransfer() { $this->respondWith = 'FAIL_ON_TRANSFER'; } public function send($url, $method, $body, array $headers, $timeOut) { // Could be start, transfer or finish if (strpos($body, 'transfer') !== false) { return $this->respondTransfer(); } elseif (strpos($body, 'finish') !== false) { return $this->respondFinish(); } return $this->respondStart(); } private function respondStart() { if ($this->respondWith == 'FAIL_ON_START') { return new GraphRawResponse( "HTTP/1.1 500 OK\r\nFoo: Bar", '{"error":{"message":"Error validating access token: Session has expired on Monday, ' . '10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",' . '"type":"OAuthException","code":190,"error_subcode":463}}' ); } return new GraphRawResponse( "HTTP/1.1 200 OK\r\nFoo: Bar", '{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}' ); } private function respondTransfer() { if ($this->respondWith == 'FAIL_ON_TRANSFER') { return new GraphRawResponse( "HTTP/1.1 500 OK\r\nFoo: Bar", '{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' . '"type":"FacebookApiException","code":6000,"error_subcode":1363019}}' ); } switch ($this->transferCount) { case 0: $data = ['start_offset' => 20, 'end_offset' => 40]; break; case 1: $data = ['start_offset' => 40, 'end_offset' => 50]; break; default: $data = ['start_offset' => 50, 'end_offset' => 50]; break; } $this->transferCount++; return new GraphRawResponse( "HTTP/1.1 200 OK\r\nFoo: Bar", json_encode($data) ); } private function respondFinish() { return new GraphRawResponse( "HTTP/1.1 200 OK\r\nFoo: Bar", '{"success":true}' ); } }