Skip to content

Commit

Permalink
Issue #62: Port status tests to expression language.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Nov 7, 2017
1 parent 4690320 commit 87e0fd3
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 218 deletions.
62 changes: 7 additions & 55 deletions tests/src/Messages/Responses/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,25 @@
class StatusTest extends AbstractTest
{
/**
* Test parsing.
*
* @param string $xml
* @param array $identifier
* @param array $statuses
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $identifier, $statuses)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()->get('response.status')->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);
}
}
}

/**
* Test validation.
*
* @param string $xml
* @param array $expectations
*
* @dataProvider statusProvider
*/
public function testValidation($xml, array $expectations)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()->get('response.status')->withXml($xml);
foreach ($expectations as $method => $result) {
if (is_array($result) && is_numeric(key($result))) {
foreach ($result as $key => $values) {
$object = $message->$method()[$key];
foreach ($values as $method => $result) {
expect($object->$method())->to->equal($result);
}
}
} elseif (is_array($result) && !is_numeric(key($result))) {
$object = $message->$method();
foreach ($result as $key => $value) {
expect($object->$key())->to->equal($value);
}
} else {
expect($message->$method())->to->equal($result);
}
}
$message = $this->getContainer()
->get('response.status')
->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
* @return array
*/
public function parserProvider()
{
return Yaml::parse($this->getFixture('factories/with-xml/status.yml'));
}

/**
* @return array
*/
public function statusProvider()
{
return Yaml::parse($this->getFixture('status.yml'));
return Yaml::parse($this->getFixture('factories/with-xml/responses/status.yml'));
}
}
150 changes: 150 additions & 0 deletions tests/src/fixtures/factories/with-xml/responses/status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
-
xml:
<POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<request communication="asynchrone" id="DGT/2017/0001/01/00/ABC" type="status">
<demandeId>
<codeDemandeur>DGT</codeDemandeur>
<annee>2017</annee>
<numero>0001</numero>
<version>01</version>
<partie>00</partie>
<produit>ABC</produit>
</demandeId>
<status code="0" type="request">
<statusDate format="dd/mm/yyyy">15/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:30:00</statusTime>
<statusMessage>OK</statusMessage>
</status>
<status code="0" type="demande">
<statusDate format="dd/mm/yyyy">17/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:20:00</statusTime>
<statusMessage>OK</statusMessage>
</status>
</request>
</POETRY>

expressions:
- message.getIdentifier().getCode() == "DGT"
- message.getIdentifier().getYear() == "2017"
- message.getIdentifier().getNumber() == "0001"
- message.getIdentifier().getVersion() == "01"
- message.getIdentifier().getPart() == "00"
- message.getIdentifier().getProduct() == "ABC"
- message.getStatuses()[0].getDate() == "15/01/2017"
- message.getStatuses()[0].getTime() == "12:30:00"
- message.getStatuses()[0].getMessage() == "OK"
- message.getStatuses()[0].getCode() == "0"
- message.getStatuses()[0].getType() == "request"
- message.getStatuses()[1].getDate() == "17/01/2017"
- message.getStatuses()[1].getTime() == "12:20:00"
- message.getStatuses()[1].getMessage() == "OK"
- message.getStatuses()[1].getCode() == "0"
- message.getStatuses()[1].getType() == "demande"

-
xml:
<POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<request communication="asynchrone" id="DGT/2017/0001/01/00/ABC" type="status">
<demandeId>
<codeDemandeur>DGT</codeDemandeur>
<annee>2017</annee>
<numero>0001</numero>
<version>01</version>
<partie>00</partie>
<produit>ABC</produit>
</demandeId>
<status code="0" type="request">
<statusDate format="dd/mm/yyyy">15/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:30:00</statusTime>
<statusMessage>OK</statusMessage>
</status>
<status code="0" type="demande">
<statusDate format="dd/mm/yyyy">17/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:20:00</statusTime>
<statusMessage>OK</statusMessage>
</status>
</request>
</POETRY>

expressions:
- message.isSuccessful() == true
- message.hasErrors() == false
- message.hasWarnings() == false
- message.countErrors() == 0
- message.countWarnings() == 0
- message.hasDemandStatus() == true
- message.hasRequestStatus() == true
- message.hasAttributionStatuses() == false
- message.getRequestStatus().getCode() == '0'
- message.getRequestStatus().getMessage() == 'OK'
- message.getDemandStatus().getCode() == '0'
- message.getDemandStatus().getMessage() == 'OK'

-
xml:
<POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<request communication="asynchrone" id="DGT/2017/0001/01/00/ABC" type="status">
<demandeId>
<codeDemandeur>DGT</codeDemandeur>
<annee>2017</annee>
<numero>0001</numero>
<version>01</version>
<partie>00</partie>
<produit>ABC</produit>
</demandeId>
<status code="1" type="request">
<statusDate format="dd/mm/yyyy">15/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:30:00</statusTime>
<statusMessage>Passed with 1 warning</statusMessage>
</status>
<status code="-1" type="demande">
<statusDate format="dd/mm/yyyy">17/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:20:00</statusTime>
<statusMessage>ID already exist</statusMessage>
</status>
</request>
</POETRY>

expressions:
- message.isSuccessful() == false
- message.hasErrors() == true
- message.hasWarnings() == true
- message.countErrors() == 1
- message.countWarnings() == 1
- message.getErrors()[0].getMessage() == "ID already exist"
- message.getWarnings()[0].getMessage() == "Passed with 1 warning"
- message.hasDemandStatus() == true
- message.hasRequestStatus() == true
- message.hasAttributionStatuses() == false
- message.getRequestStatus().getCode() == '1'
- message.getRequestStatus().getMessage() == 'Passed with 1 warning'
- message.getDemandStatus().getCode() == '-1'
- message.getDemandStatus().getMessage() == 'ID already exist'

-
xml:
<POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<request communication="asynchrone" id="DGT/2017/0001/01/00/ABC" type="status">
<demandeId>
<codeDemandeur>DGT</codeDemandeur>
<annee>2017</annee>
<numero>0001</numero>
<version>01</version>
<partie>00</partie>
<produit>ABC</produit>
</demandeId>
<status code="1" type="attribution">
<statusDate format="dd/mm/yyyy">15/01/2017</statusDate>
<statusTime format="hh:mm:ss">12:30:00</statusTime>
<statusMessage>OK</statusMessage>
</status>
</request>
</POETRY>

expressions:
- message.hasDemandStatus() == false
- message.hasRequestStatus() == false
- message.hasAttributionStatuses() == true
- message.getAttributionStatuses()[0].getCode() == '1'
- message.getAttributionStatuses()[0].getType() == 'attribution'
- message.getAttributionStatuses()[0].getMessage() == "OK"
46 changes: 0 additions & 46 deletions tests/src/fixtures/factories/with-xml/status.yml

This file was deleted.

117 changes: 0 additions & 117 deletions tests/src/fixtures/status.yml

This file was deleted.

0 comments on commit 87e0fd3

Please sign in to comment.