You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
862 B

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. namespace p3k\WebSub\Tests;
  3. // Stands in for p3k\HTTP: returns canned responses and records each request
  4. class FakeHTTP {
  5. public $requests = [];
  6. private $responses;
  7. public function __construct($responses=[]) {
  8. $this->responses = $responses;
  9. }
  10. public function head($url) {
  11. return $this->respond('HEAD', $url);
  12. }
  13. public function get($url) {
  14. return $this->respond('GET', $url);
  15. }
  16. public function post($url, $body) {
  17. return $this->respond('POST', $url, $body);
  18. }
  19. private function respond($method, $url, $body=null) {
  20. $this->requests[] = ['method' => $method, 'url' => $url, 'body' => $body];
  21. $response = isset($this->responses[$method]) ? $this->responses[$method] : [];
  22. return array_merge([
  23. 'code' => 200,
  24. 'headers' => [],
  25. 'rels' => [],
  26. 'body' => '',
  27. ], $response);
  28. }
  29. }