baseUrl = $parameters['baseUrl']; $this->adminUser = $parameters['admin']; // in case of ci deployment we take the server url from the environment $testServerUrl = getenv('TEST_SERVER_URL'); if ($testServerUrl !== false) { $this->baseUrl = $testServerUrl; } } /** * @When /^sending "([^"]*)" to "([^"]*)"$/ */ public function sendingTo($verb, $url) { $this->sendingToWith($verb, $url, null); } /** * @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) { $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; $client = new Client(); $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } $this->response = $client->get($fullUrl, $options); PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); } /** * @Given /^user "([^"]*)" does not exist$/ */ public function userDoesNotExist($user) { try { $this->userExists($user); } catch (\GuzzleHttp\Exception\ClientException $ex) { PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); } } /** * @When /^creating the user "([^"]*)r"$/ */ public function creatingTheUser($user) { $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; $client = new Client(); $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } $this->response = $client->post($fullUrl, [ 'form_params' => [ 'userid' => $user, 'password' => '123456' ] ]); PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); } /** * @When /^sending "([^"]*)" to "([^"]*)" with$/ * @param \Behat\Gherkin\Node\TableNode|null $formData */ public function sendingToWith($verb, $url, $body) { $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url; $client = new Client(); $options = []; if ($this->currentUser === 'admin') { $options['auth'] = $this->adminUser; } if ($body instanceof \Behat\Gherkin\Node\TableNode) { $fd = $body->getRowsHash(); $options['body'] = $fd; } try { $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); } } }