diff --git a/CHANGELOG.md b/CHANGELOG.md index 112b28b..dd646a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] +## [1.1.0] - 2015-10-01 +### Added +- Guzzle http client is configurable +### Fixed +- psr-4 namespace end with a namespace separator in composer.json + ## [1.0.0] - 2015-08-13 -### Changed +### Added - Password grant type feature and implemented steps - Refresh token grant type feature and implemented steps \ No newline at end of file diff --git a/README.md b/README.md index e657b4b..644f51b 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,14 @@ For others requirements please see the [composer.json](composer.json) file. "type": "vcs", "url": "git@github.com:rstgroup/behat-oauth2-context.git" } - } + ] ``` 2. Run `composer update rstgroup/behat-oauth2-context` to ensure the library is installed. ## Configuration -Copy behat.yml.dist file as behat.yml to your home project directory or copy contents from this file to your yml file with Behat tests. +Copy `behat.yml.dist` file as `behat.yml` to your home project directory or copy contents from this file to your yml file with Behat tests. You must replace sample content to right option: ```php paths: @@ -41,8 +41,8 @@ for example: - %paths.base%/vendor/rstgroup/behat-oauth2-context/features/ ``` And next you must replace parameters option: -- token_url - your url to token -- oauth2 - your data for OAuth2 authorization +- `token_url` - your url to token +- `oauth2` - your data for OAuth2 authorization ### Recommended and optional parameters diff --git a/behat.yml.dist b/behat.yml.dist index 8291d5c..dc2440e 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -4,7 +4,7 @@ default: paths: - %paths.base%/features contexts: - - RstGroup\Behat\OAuth2\Context: + - RstGroup\Behat\OAuth2\Context\OAuth2Context: parameters: token_url: some_url oauth2: @@ -18,3 +18,4 @@ default: refresh_token : true error_description : true scope : true + guzzle_parameters: #configuration for guzzle http client diff --git a/composer.json b/composer.json index 115af5b..06600fb 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "guzzlehttp/guzzle": "^5.1" }, "autoload":{ - "psr-4" : {"RstGroup\\Behat\\OAuth2\\Context": "src/"} + "psr-4" : {"RstGroup\\Behat\\OAuth2\\Context\\": "src/"} } } diff --git a/src/OAuth2Context.php b/src/OAuth2Context.php index 295af59..3538570 100644 --- a/src/OAuth2Context.php +++ b/src/OAuth2Context.php @@ -16,6 +16,8 @@ */ class OAuth2Context implements SnippetAcceptingContext { + const GUZZLE_PARAMETERS = 'guzzle_parameters'; + protected $headers = []; /** @@ -56,7 +58,9 @@ public function __construct(array $parameters) { // Initialize your context here $this->parameters = $parameters; - $this->client = new GuzzleHttpClient(); + + $guzzleParameters = $this->getGuzzleParameters(); + $this->client = new GuzzleHttpClient($guzzleParameters); $timezone = ini_get('date.timezone'); @@ -222,7 +226,7 @@ public function theResponseHasAPropertyAndItIsEquals($propertyName, $propertyVal */ public function echoLastResponse() { - $this->printDebug(sprintf("Request:\n %s Response:\n %s", $this->request, $this->response)); + $this->printDebug(sprintf("Request:\n %s \n\n Response:\n %s", $this->request, $this->response)); } /** @@ -250,7 +254,8 @@ public function theResponseHasTheOAuth2Format() */ protected function getPostResponseFromUrl($url, $body) { - return $this->client->post($url, ['body' => $body, 'verify' => false, 'exceptions' => false]); + $this->request = $this->client->createRequest('POST', $url, ['body' => $body, 'verify' => false, 'exceptions' => false]); + return $this->client->send($this->request); } /** @@ -308,6 +313,11 @@ protected function setHeaders(array $headers) } } + protected function getGuzzleParameters() + { + return isset($this->parameters[self::GUZZLE_PARAMETERS]) && is_array($this->parameters[self::GUZZLE_PARAMETERS]) ? $this->parameters[self::GUZZLE_PARAMETERS] : []; + } + /** * Prints beautified debug string. *