Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Kopacz committed Oct 1, 2015
2 parents 960e2ae + fddf343 commit f55c3ed
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ For others requirements please see the [composer.json](composer.json) file.
"type": "vcs",
"url": "[email protected]: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:
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -18,3 +18,4 @@ default:
refresh_token : true
error_description : true
scope : true
guzzle_parameters: #configuration for guzzle http client
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"guzzlehttp/guzzle": "^5.1"
},
"autoload":{
"psr-4" : {"RstGroup\\Behat\\OAuth2\\Context": "src/"}
"psr-4" : {"RstGroup\\Behat\\OAuth2\\Context\\": "src/"}
}

}
16 changes: 13 additions & 3 deletions src/OAuth2Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class OAuth2Context implements SnippetAcceptingContext
{
const GUZZLE_PARAMETERS = 'guzzle_parameters';

protected $headers = [];

/**
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit f55c3ed

Please sign in to comment.