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'
20 * Sets the mock connection adapter
22 * @param string|Net_Url2 Request URL
23 * @param string Request method
24 * @param array Configuration for this Request instance
26 public function __construct(
27 $url = null, $method = self::METHOD_GET, array $config = array()
29 parent::__construct($url, $method, $config);
30 $this->setAdapter(new HTTP_Request2_Adapter_Mock());
36 * Sends the request and returns the response.
37 * When the host is three-letter numeric string, it
38 * is used as HTTP response status code. No "proper" content
39 * is returned in that case.
41 * @return HTTP_Request2_Response
43 * @throws HTTP_Request2_Exception When the path is not mapped, or
44 * the mapped file does not exist
46 public function send()
48 $host = $this->url->getHost();
49 if (strlen($host) == 3 && is_numeric($host)) {
50 $this->adapter->addResponse(
51 "HTTP/1.0 $host dummy\n\nnothing"
53 return parent::send();
56 $path = $this->url->getPath();
57 if (!isset(self::$mapping[$path])) {
58 throw new HTTP_Request2_Exception(
59 'No predefined response for path: ' . $path
63 $file = dirname(__FILE__) . '/../' . self::$mapping[$path];
64 if (!file_exists($file)) {
65 throw new HTTP_Request2_Exception(
66 'Response file does not exist: ' . $file
70 $this->adapter->addResponse(
73 . file_get_contents($file)
76 return parent::send();