2 require_once 'HTTP/Request2.php';
3 require_once 'HTTP/Request2/Adapter/Mock.php';
5 class Wrt3g_DummyRequest extends HTTP_Request2
8 * Maps request paths (i.e. "/index.php") to files containing the HTML body
12 public static $mapping = array(
13 '/Status_NoAuth.asp' => 'tests/status_noauth-connected.htm',
14 '/index_wstatus1.asp' => 'tests/index_wstatus1-connected-excellent.htm',
15 '/index_wstatus2.asp' => 'tests/index_wstatus2-connected.htm'
21 * Sets the mock connection adapter
23 * @param string|Net_Url2 Request URL
24 * @param string Request method
25 * @param array Configuration for this Request instance
27 public function __construct(
28 $url = null, $method = self::METHOD_GET, array $config = array()
30 parent::__construct($url, $method, $config);
31 $this->setAdapter(new HTTP_Request2_Adapter_Mock());
37 * Sends the request and returns the response.
38 * When the host is three-letter numeric string, it
39 * is used as HTTP response status code. No "proper" content
40 * is returned in that case.
42 * @return HTTP_Request2_Response
44 * @throws HTTP_Request2_Exception When the path is not mapped, or
45 * the mapped file does not exist
47 public function send()
49 $host = $this->url->getHost();
50 if (strlen($host) == 3 && is_numeric($host)) {
51 $this->adapter->addResponse(
52 "HTTP/1.0 $host dummy\n\nnothing"
54 return parent::send();
57 $path = $this->url->getPath();
58 if (!isset(self::$mapping[$path])) {
59 throw new HTTP_Request2_Exception(
60 'No predefined response for path: ' . $path
64 $file = dirname(__FILE__) . '/../' . self::$mapping[$path];
65 if (!file_exists($file)) {
66 throw new HTTP_Request2_Exception(
67 'Response file does not exist: ' . $file
71 $this->adapter->addResponse(
74 . file_get_contents($file)
77 return parent::send();