baseUrl = $parameters['baseUrl']; $this->adminUser = $parameters['admin']; } /** * @When /^sending "([^"]*)" to "([^"]*)"$/ */ public function sendingTo($verb, $url) { $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url; $client = new Client(); // TODO: get admin user from config $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } try { $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); } } /** * @Then /^the status code should be "([^"]*)"$/ */ public function theStatusCodeShouldBe($statusCode) { PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode()); } /** * @Given /^As an "([^"]*)"$/ */ public function asAn($user) { $this->currentUser = $user; } /** * @Given /^using api version "([^"]*)"$/ */ public function usingApiVersion($version) { $this->apiVersion = $version; } /** * @Given /^user "([^"]*)" exists$/ */ public function userExists($user) { throw new \Behat\Behat\Exception\PendingException(); } }