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
38 * @return HTTP_Request2_Response
40 * @throws HTTP_Request2_Exception When the path is not mapped, or
41 * the mapped file does not exist
43 public function send()
45 $host = $this->url->getHost();
46 if (strlen($host) == 3 && is_numeric($host)) {
47 $this->adapter->addResponse(
48 "HTTP/1.0 $host dummy\n\nnothing"
50 return parent::send();
53 $path = $this->url->getPath();
54 if (!isset(self::$mapping[$path])) {
55 throw new HTTP_Request2_Exception(
56 'No predefined response for path: ' . $path
60 $file = dirname(__FILE__) . '/../' . self::$mapping[$path];
61 if (!file_exists($file)) {
62 throw new HTTP_Request2_Exception(
63 'Response file does not exist: ' . $file
67 $this->adapter->addResponse(
70 . file_get_contents($file)
73 return parent::send();