|
|
|
@ -11,11 +11,11 @@ require __DIR__ . '/../../vendor/autoload.php'; |
|
|
|
*/ |
|
|
|
class FeatureContext extends BehatContext { |
|
|
|
|
|
|
|
/** @var string */ |
|
|
|
private $baseUrl = ''; |
|
|
|
/** @var string */ |
|
|
|
private $baseUrl = ''; |
|
|
|
|
|
|
|
/** @var ResponseInterface */ |
|
|
|
private $response = null; |
|
|
|
/** @var ResponseInterface */ |
|
|
|
private $response = null; |
|
|
|
|
|
|
|
/** @var string */ |
|
|
|
private $currentUser = ''; |
|
|
|
@ -23,51 +23,39 @@ class FeatureContext extends BehatContext { |
|
|
|
/** @var int */ |
|
|
|
private $apiVersion = 1; |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes context. |
|
|
|
* Every scenario gets it's own context object. |
|
|
|
* |
|
|
|
* @param array $parameters context parameters (set them up through behat.yml) |
|
|
|
*/ |
|
|
|
public function __construct(array $parameters) { |
|
|
|
/** |
|
|
|
* Initializes context. |
|
|
|
* Every scenario gets it's own context object. |
|
|
|
* |
|
|
|
* @param array $parameters context parameters (set them up through behat.yml) |
|
|
|
*/ |
|
|
|
public function __construct(array $parameters) { |
|
|
|
|
|
|
|
// Initialize your context here
|
|
|
|
// Initialize your context here
|
|
|
|
$this->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) { |
|
|
|
/** |
|
|
|
* @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 "([^"]*)"$/
|
|
|
|
@ -80,7 +68,69 @@ class FeatureContext extends BehatContext { |
|
|
|
* @Given /^user "([^"]*)" exists$/
|
|
|
|
*/ |
|
|
|
public function userExists($user) { |
|
|
|
throw new \Behat\Behat\Exception\PendingException(); |
|
|
|
$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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |