Skip to content

Commit

Permalink
Issue #11: Temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Dec 1, 2017
1 parent ccbd6f3 commit 2ff3361
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "EUPL-1.1",
"require": {
"ec-europa/oe-poetry-client": "~0",
"symfony/expression-language": "^2.8 || ^3.0",
"internations/http-mock": "^0.8",
"behat/behat": "^3",
"phpunit/phpunit": "^5"
Expand Down
4 changes: 4 additions & 0 deletions features/responses.feature
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ Feature: Server responses
</documentSourceLang>
</documentSource>
"""

And Poetry service received "request.create_review_request" request should satisfy the following expressions:
| request.getIdentifier().getCode() | STSI |
| request.getIdentifier().getYear() | 2017 |
43 changes: 34 additions & 9 deletions src/Context/PoetryContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use EC\Behat\PoetryExtension\Context\Services\Assert;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

/**
* Class PoetryContext
Expand Down Expand Up @@ -131,13 +132,7 @@ public function assertServiceRequest(PyStringNode $string)
*/
public function assertPartialServiceRequest(TableNode $table)
{
/** @var \EC\Poetry\Services\Parser $parser */
$requests = $this->poetryMock->getHttp()->requests;
if ($requests->count() == 0) {
throw new \InvalidArgumentException("No request was performed on the mock Poetry service");
}

$message = $this->extractSoapBody((string) $requests->latest()->getBody());
$message = $this->getLastRequest();
$parser = $this->poetry->get('parser');
$parser->addXmlContent($message);
foreach ($table->getRows() as $row) {
Expand All @@ -151,17 +146,47 @@ public function assertPartialServiceRequest(TableNode $table)
* @Then Poetry service received request should contain the following XML portion:
*/
public function assertPartialXmlServiceRequest(PyStringNode $string)
{
Assert::assertContainsXml($string->getRaw(), $this->getLastRequest());
}

/**
* @param string $name
* @param \Behat\Gherkin\Node\TableNode $table
*
* @Then Poetry service received :name request should satisfy the following expressions:
*/
public function assertExpressionsOnRequest($name, TableNode $table)
{
$language = new ExpressionLanguage();
$message = $this->getLastRequest();
/** @var \EC\Poetry\Messages\Requests\AbstractRequest $request */
$request = $this->poetry->get($name)->fromXml($message);

foreach ($table->getRowsHash() as $expression => $expected) {
$language->evaluate($expression, ['request' => $request]);
}
}

/**
* @return string
*/
protected function getLastRequest()
{
/** @var \EC\Poetry\Services\Parser $parser */
$requests = $this->poetryMock->getHttp()->requests;
if ($requests->count() == 0) {
throw new \InvalidArgumentException("No request was performed on the mock Poetry service");
}

$contains = $string->getRaw();
Assert::assertContainsXml($contains, $this->extractSoapBody((string) $requests->latest()->getBody()));
return $this->extractSoapBody((string) $requests->latest()->getBody());
}

/**
* @param string $body
*
* @return string
*/
protected function extractSoapBody($body)
{
$parser = $this->poetry->get('parser');
Expand Down

0 comments on commit 2ff3361

Please sign in to comment.