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'
19 * Sets the mock connection adapter
21 * @param string|Net_Url2 Request URL
22 * @param string Request method
23 * @param array Configuration for this Request instance
25 public function __construct(
26 $url = null, $method = self::METHOD_GET, array $config = array()
28 parent::__construct($url, $method, $config);
29 $this->setAdapter(new HTTP_Request2_Adapter_Mock());
35 * Sends the request and returns the response
37 * @return HTTP_Request2_Response
39 * @throws HTTP_Request2_Exception When the path is not mapped, or
40 * the mapped file does not exist
42 public function send()
44 $path = $this->url->getPath();
45 if (!isset(self::$mapping[$path])) {
46 throw new HTTP_Request2_Exception(
47 'No predefined response for path: ' . $path
51 $file = dirname(__FILE__) . '/../' . self::$mapping[$path];
52 if (!file_exists($file)) {
53 throw new HTTP_Request2_Exception(
54 'Response file does not exist: ' . $file
58 $this->adapter->addResponse(
61 . file_get_contents($file)
64 return parent::send();