diff options
Diffstat (limited to 'Twilio/Tests/Holodeck.php')
-rw-r--r-- | Twilio/Tests/Holodeck.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Twilio/Tests/Holodeck.php b/Twilio/Tests/Holodeck.php index 3b3b4fc..6a67f98 100644 --- a/Twilio/Tests/Holodeck.php +++ b/Twilio/Tests/Holodeck.php @@ -27,6 +27,22 @@ class Holodeck implements Client { $this->response = $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"; + $message .= "Candidate Requests:\n"; + 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]; @@ -40,4 +56,18 @@ class Holodeck implements Client { 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)); + } } |