Skip to content

Commit 6f1099f

Browse files
committed
Merge pull request #9 from teaandcode/develop
Merge Develop into Master
2 parents e3173e3 + c855742 commit 6f1099f

5 files changed

Lines changed: 104 additions & 8 deletions

File tree

config/service.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
{
22
"name": "Travis API",
33
"operations": {
4+
"GetConfig": {
5+
"httpMethod": "GET",
6+
"uri": "config",
7+
"summary": "Gets the config"
8+
},
49
"GetReposBuilds": {
510
"httpMethod": "GET",
6-
"uri": "repos/{slug}/builds",
11+
"uri": "repos/{profile}/{repo}/builds",
712
"summary": "Gets the last build for repo",
813
"parameters": {
9-
"slug": {
14+
"profile": {
15+
"location": "uri",
16+
"description": "Profile name from GitHub",
17+
"required": true
18+
},
19+
"repo": {
1020
"location": "uri",
11-
"description": "Repo slug from GitHub",
21+
"description": "Repo name from GitHub",
1222
"required": true
1323
},
1424
"number": {

features/repo.feature

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
Feature: Repo
22
As a user
3-
I would like to see build details for a repo
3+
I would like to see the config and build details for a repo
4+
5+
Scenario: Getting the config
6+
When I call "GetConfig"
7+
Then I get a successful response
8+
And the response contains the following values from JSON:
9+
"""
10+
{
11+
"config": {
12+
"host": "travis-ci.org",
13+
"github": {
14+
"scopes": [
15+
"read:org"
16+
]
17+
}
18+
}
19+
}
20+
"""
421

522
Scenario: Getting the first build
623
When I call "GetReposBuilds" with the following values:
7-
| slug | teaandcode/behat-guzzle-extension |
8-
| number | 1 |
24+
| profile | teaandcode |
25+
| repo | behat-guzzle-extension |
26+
| number | 1 |
927
Then I get a successful response
1028
And the response contains 1 resource with the following data:
1129
| id | repository_id | number | state |

spec/Behat/GuzzleExtension/Context/GuzzleContextSpec.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,26 @@ public function it_has_i_call_command_with_value_from_json()
151151
$this->theResponseContainsTheFollowingValue($table);
152152
}
153153

154+
public function it_has_i_call_command_with_value_from_json_and_response_contains_value_from_json()
155+
{
156+
$client = $this->getMockedClient(
157+
new Response(
158+
200,
159+
array(
160+
'Content-Type' => 'application/json'
161+
),
162+
'{"foo":"bar","fu":[{"id":4},{"id":6}]}'
163+
)
164+
);
165+
166+
$string = new PyStringNode(array('{"test":"foo"}'), 1);
167+
$table = new PyStringNode(array('{"foo":"bar","fu":[{"id":4}]}'), 1);
168+
169+
$this->setGuzzleClient($client);
170+
$this->iCallCommandWithValueFromJSON('Mock', $string);
171+
$this->theResponseContainsTheFollowingValueFromJSON($table);
172+
}
173+
154174
public function it_has_i_call_command_but_response_contains_a_wrong_value()
155175
{
156176
$client = $this->getMockedClient(

src/Behat/GuzzleExtension/Context/GuzzleContext.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,31 @@ public function theResponseContainsTheFollowingValue(TableNode $table)
298298
$this->compareValues($item, $data);
299299
}
300300

301+
/**
302+
* Check response contains specified values from JSON
303+
*
304+
* Example: The the response contains the following values from JSON:
305+
* """
306+
* """
307+
* Example: And the response contains the following value from JSON:
308+
* """
309+
* """
310+
*
311+
* @param PyStringNode $string Values specified in feature as JSON
312+
*
313+
* @Then the response contains the following value(s) from JSON:
314+
*/
315+
public function theResponseContainsTheFollowingValueFromJSON(
316+
PyStringNode $string
317+
) {
318+
$data = json_decode($string, true);
319+
$item = $this->getGuzzleResult();
320+
321+
$data = $this->addStoredValuesToArray($data);
322+
323+
$this->compareValues($item, $data);
324+
}
325+
301326
/**
302327
*
303328
* Example: Then the response contains 2 resources with the following data:
@@ -317,7 +342,7 @@ public function theResponseContainsResourceWithTheFollowingData(
317342
$count,
318343
TableNode $table
319344
) {
320-
$list = $this->getGuzzleResult();
345+
$list = $this->getGuzzleResult();
321346
$length = count($list);
322347

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

403428
return $string;
404429
}
430+
431+
/**
432+
* Adds stored values to array
433+
*
434+
* @param array $array Array containing stored field markers
435+
*
436+
* @access protected
437+
* @return array
438+
*/
439+
protected function addStoredValuesToArray($array)
440+
{
441+
foreach ($array as $field => $value) {
442+
if (is_array($value)) {
443+
$value = $this->addStoredValuesToArray($value);
444+
} else {
445+
$value = $this->addStoredValues($value);
446+
}
447+
448+
$array[$field] = $value;
449+
}
450+
451+
return $array;
452+
}
405453
}

src/Behat/GuzzleExtension/Context/RawGuzzleContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RawGuzzleContext implements GuzzleAwareContext
3838
/**
3939
* @var string
4040
*/
41-
const GUZZLE_EXTENSION_VERSION = '0.3.5';
41+
const GUZZLE_EXTENSION_VERSION = '0.3.6';
4242

4343
/**
4444
* @var Client

0 commit comments

Comments
 (0)