Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Develop into Master #9

Merged
merged 2 commits into from
Jun 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions config/service.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{
"name": "Travis API",
"operations": {
"GetConfig": {
"httpMethod": "GET",
"uri": "config",
"summary": "Gets the config"
},
"GetReposBuilds": {
"httpMethod": "GET",
"uri": "repos/{slug}/builds",
"uri": "repos/{profile}/{repo}/builds",
"summary": "Gets the last build for repo",
"parameters": {
"slug": {
"profile": {
"location": "uri",
"description": "Profile name from GitHub",
"required": true
},
"repo": {
"location": "uri",
"description": "Repo slug from GitHub",
"description": "Repo name from GitHub",
"required": true
},
"number": {
Expand Down
24 changes: 21 additions & 3 deletions features/repo.feature
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
Feature: Repo
As a user
I would like to see build details for a repo
I would like to see the config and build details for a repo

Scenario: Getting the config
When I call "GetConfig"
Then I get a successful response
And the response contains the following values from JSON:
"""
{
"config": {
"host": "travis-ci.org",
"github": {
"scopes": [
"read:org"
]
}
}
}
"""

Scenario: Getting the first build
When I call "GetReposBuilds" with the following values:
| slug | teaandcode/behat-guzzle-extension |
| number | 1 |
| profile | teaandcode |
| repo | behat-guzzle-extension |
| number | 1 |
Then I get a successful response
And the response contains 1 resource with the following data:
| id | repository_id | number | state |
Expand Down
20 changes: 20 additions & 0 deletions spec/Behat/GuzzleExtension/Context/GuzzleContextSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ public function it_has_i_call_command_with_value_from_json()
$this->theResponseContainsTheFollowingValue($table);
}

public function it_has_i_call_command_with_value_from_json_and_response_contains_value_from_json()
{
$client = $this->getMockedClient(
new Response(
200,
array(
'Content-Type' => 'application/json'
),
'{"foo":"bar","fu":[{"id":4},{"id":6}]}'
)
);

$string = new PyStringNode(array('{"test":"foo"}'), 1);
$table = new PyStringNode(array('{"foo":"bar","fu":[{"id":4}]}'), 1);

$this->setGuzzleClient($client);
$this->iCallCommandWithValueFromJSON('Mock', $string);
$this->theResponseContainsTheFollowingValueFromJSON($table);
}

public function it_has_i_call_command_but_response_contains_a_wrong_value()
{
$client = $this->getMockedClient(
Expand Down
50 changes: 49 additions & 1 deletion src/Behat/GuzzleExtension/Context/GuzzleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,31 @@ public function theResponseContainsTheFollowingValue(TableNode $table)
$this->compareValues($item, $data);
}

/**
* Check response contains specified values from JSON
*
* Example: The the response contains the following values from JSON:
* """
* """
* Example: And the response contains the following value from JSON:
* """
* """
*
* @param PyStringNode $string Values specified in feature as JSON
*
* @Then the response contains the following value(s) from JSON:
*/
public function theResponseContainsTheFollowingValueFromJSON(
PyStringNode $string
) {
$data = json_decode($string, true);
$item = $this->getGuzzleResult();

$data = $this->addStoredValuesToArray($data);

$this->compareValues($item, $data);
}

/**
*
* Example: Then the response contains 2 resources with the following data:
Expand All @@ -317,7 +342,7 @@ public function theResponseContainsResourceWithTheFollowingData(
$count,
TableNode $table
) {
$list = $this->getGuzzleResult();
$list = $this->getGuzzleResult();
$length = count($list);

if ($length != $count) {
Expand Down Expand Up @@ -402,4 +427,27 @@ protected function addStoredValues($string)

return $string;
}

/**
* Adds stored values to array
*
* @param array $array Array containing stored field markers
*
* @access protected
* @return array
*/
protected function addStoredValuesToArray($array)
{
foreach ($array as $field => $value) {
if (is_array($value)) {
$value = $this->addStoredValuesToArray($value);
} else {
$value = $this->addStoredValues($value);
}

$array[$field] = $value;
}

return $array;
}
}
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.5';
const GUZZLE_EXTENSION_VERSION = '0.3.6';

/**
* @var Client
Expand Down