public function makeRequest($method, $url, $data = array()) { global $map; # append params to url (for fixtures) $uri = str_replace($this->app->baseUri, '', $url); if ($method == 'GET' && !empty($data)) { $uri = $uri . '?' . http_build_query($data); } # extract response map parameters # $status = $map[$method][$uri][0]; $resource = $map[$method][$uri][1]; # record the request $this->addRequest($method, $uri, $data); # load response from fixture and return data $mock_data = MockData::load($resource); if (!$mock_data) { $msg = 'Unable to connect to the AWeber API. Please ensure that CURL is enabled and your '; $msg .= 'firewall allows outbound SSL requests from your web server.'; $error = array('message' => $msg, 'type' => 'APIUnreachableError', 'documentation_url' => 'https://labs.aweber.com/docs/troubleshooting'); throw new AWeberAPIException($error, $url); } $headers = array(); $headers['Status-Code'] = $status; if ($status == 201) { $headers['Location'] = $resource; } $mock_data->headers = $headers; if ($headers['Status-Code'] >= 400) { $data = json_decode($mock_data->body, true); throw new AWeberAPIException($data['error'], $url); } return $mock_data; }
public function request($method, $uri, $data = array(), $options = array()) { if ($method == 'GET' && !empty($data)) { $uri = $uri . '?' . http_build_query($data); } $this->addRequest($method, $uri, $data); if (!empty($options['return']) && $options['return'] == 'status') { return $this->requests[$method][$uri]; } $data = MockData::load($this->requests[$method][$uri]); $this->parseAsError($data); return $data; }
/** * Run before each test. Sets up mock adapter, which uses fixture * data for requests, and creates a new collection. */ public function setUp() { $this->adapter = new MockOAuthAdapter(); $this->collection = new AWeberCollection(MockData::load('lists'), '/accounts/1/lists', $this->adapter); }