From 2ff33612d649787b1f009b2b940ed83ed73d7d50 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Fri, 1 Dec 2017 11:50:46 +0100 Subject: [PATCH] Issue #11: Temp. --- composer.json | 1 + features/responses.feature | 4 ++++ src/Context/PoetryContext.php | 43 +++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index cc4ca70..580c5f5 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/features/responses.feature b/features/responses.feature index 45b4fd0..1ce7313 100644 --- a/features/responses.feature +++ b/features/responses.feature @@ -190,3 +190,7 @@ Feature: Server responses """ + + And Poetry service received "request.create_review_request" request should satisfy the following expressions: + | request.getIdentifier().getCode() | STSI | + | request.getIdentifier().getYear() | 2017 | diff --git a/src/Context/PoetryContext.php b/src/Context/PoetryContext.php index 1aa2031..d9f3d6c 100644 --- a/src/Context/PoetryContext.php +++ b/src/Context/PoetryContext.php @@ -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 @@ -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) { @@ -151,6 +146,32 @@ 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; @@ -158,10 +179,14 @@ public function assertPartialXmlServiceRequest(PyStringNode $string) 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');