Skip to content

Commit

Permalink
Issue #62: Improve notification tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Nov 7, 2017
1 parent 5b5ee09 commit 4690320
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 122 deletions.
10 changes: 10 additions & 0 deletions tests/src/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Monolog\Logger;
use Peridot\Leo\Leo;
use PHPUnit\Framework\TestCase;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Validator\ConstraintViolationListInterface;

/**
Expand Down Expand Up @@ -157,4 +158,13 @@ protected function assertProperties($component, $properties)
}
}
}

protected function assertExpressions(array $expressions, $options)
{
$language = new ExpressionLanguage();
foreach ($expressions as $expression) {
$result = $language->evaluate($expression, $options);
expect($result)->to->be->true("Following expression did not evaluate: ".$expression);
}
}
}
31 changes: 8 additions & 23 deletions tests/src/Messages/Notifications/StatusUpdatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,25 @@ public function testRender()
}

/**
* Test parsing.
*
* @param string $xml
* @param array $identifier
* @param array $statuses
* @param array $targets
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $identifier, $statuses, $targets)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Notifications\StatusUpdated $message */
$message = $this->getContainer()->get('notification.status_updated')->withXml($xml);

foreach ($identifier as $method => $expected) {
expect($message->getIdentifier()->{$method}())->to->equal($expected);
}
foreach ($statuses as $index => $status) {
foreach ($status as $method => $expected) {
expect($message->getStatuses()[$index]->{$method}())->to->equal($expected);
}
}
foreach ($targets as $index => $target) {
foreach ($target as $method => $expected) {
expect($message->getTargets()[$index]->{$method}())->to->equal($expected);
}
}
/** @var \EC\Poetry\Messages\Notifications\TranslationReceived $message */
$message = $this->getContainer()
->get('notification.status_updated')
->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
* @return array
*/
public function parserProvider()
{
return Yaml::parse($this->getFixture('factories/with-xml/notifications/statusUpdated.yml'));
return Yaml::parse($this->getFixture('factories/with-xml/notifications/status-updated.yml'));
}
}
24 changes: 8 additions & 16 deletions tests/src/Messages/Notifications/TranslationReceivedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EC\Poetry\Messages\Components\Identifier;
use EC\Poetry\Messages\Notifications\TranslationReceived;
use EC\Poetry\Tests\AbstractTest;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Yaml\Yaml;

/**
Expand Down Expand Up @@ -43,34 +44,25 @@ public function testRender()
}

/**
* Test parsing.
*
* @param string $xml
* @param array $identifier
* @param array $targets
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $identifier, $targets)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Notifications\TranslationReceived $message */
$message = $this->getContainer()->get('notification.translation_received')->withXml($xml);

foreach ($identifier as $method => $expected) {
expect($message->getIdentifier()->{$method}())->to->equal($expected);
}
foreach ($targets as $index => $target) {
foreach ($target as $method => $expected) {
expect($message->getTargets()[$index]->{$method}())->to->equal($expected);
}
}
$message = $this->getContainer()
->get('notification.translation_received')
->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
* @return array
*/
public function parserProvider()
{
return Yaml::parse($this->getFixture('factories/with-xml/notifications/translationReceived.yml'));
return Yaml::parse($this->getFixture('factories/with-xml/notifications/translation-received.yml'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-
xml:
<?xml version="1.0" encoding="UTF-8"?>
<POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<request communication="synchrone" id="1069698" type="status">
<demandeId>
<codeDemandeur>WEB</codeDemandeur>
<annee>2017</annee>
<numero>40029</numero>
<version>0</version>
<partie>0</partie>
<produit>TRA</produit>
</demandeId>
<status code="0" type="request">
<statusDate>29/09/2017</statusDate>
<statusTime>15:44:02</statusTime>
<statusMessage>OK</statusMessage>
</status>
<status code="ONG" type="demande">
<statusDate>29/09/2017</statusDate>
<statusTime>15:42:34</statusTime>
<statusMessage>REQUEST ACCEPTED</statusMessage>
</status>
<status code="ONG" lgCode="FR" type="attribution">
<statusDate>29/09/2017</statusDate>
<statusTime>00:00:00</statusTime>
</status>
<attributions format="HTML" lgCode="FR">
<attributionsDelai>04/10/2017 23:59</attributionsDelai>
<attributionsDelaiAccepted>04/10/2017 23:59</attributionsDelaiAccepted>
</attributions>
</request>
</POETRY>

expressions:
- message.getIdentifier().getCode() == 'WEB'
- message.getIdentifier().getYear() == '2017'
- message.getIdentifier().getNumber() == '40029'
- message.getIdentifier().getVersion() == '0'
- message.getIdentifier().getPart() == '0'
- message.getIdentifier().getProduct() == 'TRA'
- message.getStatuses()[0].getCode() == "0"
- message.getStatuses()[0].getType() == "request"
- message.getStatuses()[0].getDate() == "29/09/2017"
- message.getStatuses()[0].getTime() == "15:44:02"
- message.getStatuses()[0].getMessage() == "OK"
- message.getStatuses()[1].getCode() == "ONG"
- message.getStatuses()[1].getType() == "demande"
- message.getStatuses()[1].getDate() == "29/09/2017"
- message.getStatuses()[1].getTime() == "15:42:34"
- message.getStatuses()[1].getMessage() == "REQUEST ACCEPTED"
- message.getStatuses()[2].getCode() == "ONG"
- message.getStatuses()[2].getType() == "attribution"
- message.getStatuses()[2].getLanguage() == "FR"
- message.getStatuses()[2].getDate() == "29/09/2017"
- message.getStatuses()[2].getTime() == "00:00:00"
- message.getTargets()[0].getFormat() == "HTML"
- message.getTargets()[0].getFormat() == "HTML"
- message.getTargets()[0].getLanguage() == "FR"
- message.getTargets()[0].getDelay() == "04/10/2017 23:59"
- message.getTargets()[0].getAcceptedDelay() == "04/10/2017 23:59"

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
</request>
</POETRY>


identifier:
getCode: "WEB"
getYear: "2017"
getNumber: "40012"
getVersion: "0"
getPart: "39"
getProduct: "TRA"

targets:
-
getFormat: "HTML"
getLanguage: "FR"
getTranslatedFile: "File64"
expressions:
- message.getIdentifier().getCode() == 'WEB'
- message.getIdentifier().getYear() == '2017'
- message.getIdentifier().getNumber() == '40012'
- message.getIdentifier().getVersion() == '0'
- message.getIdentifier().getPart() == '39'
- message.getIdentifier().getProduct() == 'TRA'
- message.getTargets()[0].getFormat() == 'HTML'
- message.getTargets()[0].getLanguage() == 'FR'
- message.getTargets()[0].getTranslatedFile() == 'File64'

0 comments on commit 4690320

Please sign in to comment.