Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Behat/GuzzleExtension/Context/RawGuzzleContext.php [FIXED]
  • Loading branch information
knasher committed Dec 21, 2016
2 parents 3c28840 + 8bfa978 commit baf10b3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.3.x-dev"
"dev-master": "0.4.x-dev"
}
}
}
29 changes: 29 additions & 0 deletions spec/Behat/GuzzleExtension/Context/GuzzleContextSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,35 @@ public function it_compares_response_body_with_a_pystring_including_stored_value
$this->theResponseBodyMatches($string);
}

public function it_should_throw_exception_when_expected_string_missing_from_actual_result()
{
$client = $this->getMockedClient(
new Response(
200,
array(
'Content-Type' => 'application/json'
),
'{"message":"E-mail address foo@bar is invalid"}'
)
);

$value = new PyStringNode(array('{"test":"foo"}'), 1);
$string = new PyStringNode(array('fu@bar'), 1);

$this->setGuzzleClient($client);
$this->iCallCommandWithValueFromJSON('Mock', $value);

$this->shouldThrow(
new ClientErrorResponseException(
'Actual response {"message":"E-mail address foo@bar is ' .
'invalid"} does not contain string fu@bar'
)
)->during(
'theResponseContainsTheFollowingString',
array($string)
);
}

public function it_should_throw_exception_when_expected_value_missing_from_array_of_actual_values()
{
$client = $this->getMockedClient(
Expand Down
32 changes: 29 additions & 3 deletions src/Behat/GuzzleExtension/Context/GuzzleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public function iGetAnUnsuccessfulResponseWithAStatusCodeOf($code)
* Example: The the response body matches the following:
* """
* Id,Name,Age,Comment
* 1,"Richard Saunders",33,"some comment"
* 2,"Dave Nash",,"another comment"
* 3,{stored[person][name]},{stored[person][age]},{stored[person][comment]}
* 1,"Richard Saunders",33,"some description"
* 2,"Dave Nash",,"another description"
* 3,{stored[person][name]},{stored[person][age]},{stored[person][desc]}
* """
*
* @param PyStringNode $body
Expand All @@ -290,6 +290,32 @@ public function theResponseBodyMatches(PyStringNode $body)
);
}

/**
* Check response contains a specified string
*
* Example: And the response contains the following string:
* """
* {stored[someArray][email][invalid]} is invalid
* """
*
* @param PyStringNode $string String specified in feature
*
* @Then the response contains the following string:
*/
public function theResponseContainsTheFollowingString(
PyStringNode $string
) {
$response = $this->getGuzzleResponse()->getBody(true);
$formatted = $this->addStoredValues($string->getRaw());

if (strpos($response, $formatted) === false) {
throw new ClientErrorResponseException(
'Actual response ' . $response . ' does not contain ' .
'string ' . $formatted
);
}
}

/**
* Check response contains specified values
*
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.9';
const GUZZLE_EXTENSION_VERSION = '0.4.0';

/**
* @var Client
Expand Down

0 comments on commit baf10b3

Please sign in to comment.