Skip to content

Instantly share code, notes, and snippets.

@kevinburke
Created December 1, 2016 18:41
Show Gist options
  • Save kevinburke/788475a0e658b3b55b7848f3f4d1c819 to your computer and use it in GitHub Desktop.
Save kevinburke/788475a0e658b3b55b7848f3f4d1c819 to your computer and use it in GitHub Desktop.
diff --git a/Twilio/Tests/Holodeck.php b/Twilio/Tests/Holodeck.php
index 6a67f989..11cc9388 100644
--- a/Twilio/Tests/Holodeck.php
+++ b/Twilio/Tests/Holodeck.php
@@ -1,37 +1,31 @@
<?php
-
namespace Twilio\Tests;
-
use Twilio\Http\Client;
use Twilio\Http\Response;
class Holodeck implements Client {
private $requests = array();
- private $response = null;
+ private $responses = array();
public function request($method, $url, $params = array(), $data = array(),
$headers = array(), $user = null, $password = null,
$timeout = null) {
array_push($this->requests, new Request($method, $url, $params, $data, $headers, $user, $password));
-
- if ($this->response == null) {
+ if (count($this->responses) === 0) {
return new Response(404, null, null);
} else {
- return $this->response;
+ return array_shift($this->responses);
}
}
-
public function mock($response) {
- $this->response = $response;
+ array_push($this->responses, $response);
}
-
public function assertRequest($request) {
if ($this->hasRequest($request)) {
return;
}
-
$message = "Failed asserting that the following request exists: \n";
$message .= ' - ' . $this->printRequest($request);
$message .= "\n" . str_repeat('-', 3) . "\n";
@@ -39,10 +33,8 @@ class Holodeck implements Client {
foreach ($this->requests as $candidate) {
$message .= ' + ' . $this->printRequest($candidate) . "\n";
}
-
throw new \PHPUnit_Framework_ExpectationFailedException($message);
}
-
public function hasRequest($request) {
for ($i = 0; $i < count($this->requests); $i++) {
$c = $this->requests[$i];
@@ -53,21 +45,16 @@ class Holodeck implements Client {
return true;
}
}
-
return false;
}
-
protected function printRequest($request) {
$url = $request->url;
if ($request->params) {
$url .= '?' . http_build_query($request->params);
}
-
-
$data = $request->data
? '-d ' . http_build_query($request->data)
: '';
-
return implode(' ', array(strtoupper($request->method), $url, $data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment