Skip to content

Commit

Permalink
Added configuration docs and trimmed trailing slashes from base_url
Browse files Browse the repository at this point in the history
  • Loading branch information
knasher committed May 14, 2015
1 parent b043e2d commit 162f2d2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
69 changes: 63 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ Guzzle extension for Behat is an integration layer between Behat 3.0+ and Guzzle
base step definitions and hooks for your contexts or subcontexts. Or it could
be even used as context on its own.

## To do

* Add documentation
* Add language support

## Installation

Add to your project with Composer (*dev*)
Expand All @@ -31,7 +26,24 @@ php composer.phar require --dev teaandcode/behat-guzzle-extension

## Configuration

### Example Configuration
The extension is designed to require very little configuration, the only two
fields it requires is a `base_url` and a `service_descriptions` file location.

The `base_url` is the root url containing either a host name or IP address of
the API you're writing tests for, just make sure it's a fully qualified URL
(the trailing slash is not required) e.g. http://127.0.0.1

The `service_descriptions` file location is required as the extension is
designed to make use of a Guzzle service descriptions file, this means that all
the endpoints and associated fields you want to test should be listed as JSON in
the file for the extension to work.

Follow the link provided here if you want to know more about how to use the
[Guzzle service descriptions](http://guzzle3.readthedocs.org/webservice-client/guzzle-service-descriptions.html)
file or take a look at the example Guzzle service descriptions file excerpt
below.

### Example configuration in behat.yml

```yaml
default:
Expand All @@ -48,6 +60,51 @@ default:
test.user.2: A6B...8E6
```
### Example Guzzle service descriptions file
```json
{
"name": "Travis API",
"operations": {
"GetReposBuilds": {
"httpMethod": "GET",
"uri": "repos/{slug}/builds",
"summary": "Gets the last build for repo",
"parameters": {
"slug": {
"location": "uri",
"description": "Repo slug from GitHub",
"required": true
},
"number": {
"location": "query"
}
}
}
}
}
```

## Further configuration

As you might have seen in the example configuration above, it is possible to
pass a list of usernames or e-mail addresses that can be associated with an HTTP
header Authorization Bearer token, which means that you're able to test secure
parts of your API. Just specify the GuzzleContext as shown above in the
behat.yml file and provide and array of users utilising the username/e-mail
address ad the key with the bearer token as the value.

## Predefined steps

TO DO: In the meantime checkout the repo.feature file in the features directory
and the docblocks above each of the methods in the GuzzleContext.php file in the
src/Behat/GuzzleExtension/Context directory.

## To do

* Add documentation
* Add language support

## Copyright

Copyright (c) 2015 Dave Nash (knasher). See LICENSE for details.
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/GuzzleExtension/Context/RawGuzzleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RawGuzzleContext implements GuzzleAwareContext
/**
* @var string
*/
const GUZZLE_EXTENSION_VERSION = '0.3.4';
const GUZZLE_EXTENSION_VERSION = '0.3.5';

/**
* @var Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public function initialize(ExtensionManager $extensionManager)
*/
public function load(ContainerBuilder $container, array $config)
{
$container->setParameter('guzzle.base_url', $config['base_url']);
$baseUrl = rtrim($config['base_url'], '/');

$container->setParameter('guzzle.base_url', $baseUrl);
$container->setParameter('guzzle.parameters', $config);

$this->loadClient($container);
Expand Down

0 comments on commit 162f2d2

Please sign in to comment.