Skip to content

Commit

Permalink
Issue #62: Port component 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 66527c8 commit 21a7066
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 176 deletions.
5 changes: 1 addition & 4 deletions tests/src/Messages/Components/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public function testValidation()
*/
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()
->get('component.contact')
->withXml($xml);
$message = $this->getContainer()->get('component.contact')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/src/Messages/Components/DetailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ public function testValidation()
*/
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()
->get('component.details')
->withXml($xml);
$message = $this->getContainer()->get('component.details')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/src/Messages/Components/IdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public function testValidation()
*/
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()
->get('component.identifier')
->withXml($xml);
$message = $this->getContainer()->get('component.identifier')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

Expand Down
15 changes: 5 additions & 10 deletions tests/src/Messages/Components/ReferenceDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,22 @@ public function testValidation()
}

/**
* Test parsing.
*
* @param string $xml
* @param array $fixtures
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $fixtures)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Components\ReferenceDocument $component */
$component = $this->getContainer()->get('component.reference_document')->withXml($xml);
foreach ($fixtures as $method => $value) {
expect($component->$method())->to->equal($value);
}
$message = $this->getContainer()->get('component.reference_document')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
* @return mixed
*/
public function parserProvider()
{
return Yaml::parse($this->getFixture('factories/with-xml/components/referenceDocument.yml'));
return Yaml::parse($this->getFixture('factories/with-xml/components/reference-document.yml'));
}
}
16 changes: 5 additions & 11 deletions tests/src/Messages/Components/ReturnAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,22 @@ public function testValidation()
}

/**
* Test parsing.
*
* @param string $xml
* @param array $fixtures
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $fixtures)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Components\ReturnAddress $component */
$component = $this->getContainer()->get('component.return_address')->withXml($xml);

foreach ($fixtures as $method => $value) {
expect($component->$method())->to->equal($value);
}
$message = $this->getContainer()->get('component.return_address')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
* @return mixed
*/
public function parserProvider()
{
return Yaml::parse($this->getFixture('factories/with-xml/components/returnAddress.yml'));
return Yaml::parse($this->getFixture('factories/with-xml/components/return-address.yml'));
}
}
20 changes: 4 additions & 16 deletions tests/src/Messages/Components/SourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,15 @@ public function testValidation()
}

/**
* Test parsing.
*
* @param string $xml
* @param array $expected
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $expected)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Components\Source $component */
$component = $this->getContainer()->get('component.source')->withXml($xml);

foreach ($expected as $getComponent => $properties) {
if ($this->isComponentCollection($properties)) {
foreach ($properties as $i => $property) {
$this->assertProperties($component->$getComponent()[$i], $property);
}
} else {
expect($component->$getComponent())->to->equal($properties);
}
}
$message = $this->getContainer()->get('component.source')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
Expand Down
20 changes: 4 additions & 16 deletions tests/src/Messages/Components/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,15 @@ public function testValidation()
}

/**
* Test parsing.
*
* @param string $xml
* @param string $date
* @param string $time
* @param string $message
* @param string $code
* @param string $type
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $date, $time, $message, $code, $type)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Components\Status $component */
$component = $this->getContainer()->get('component.status')->withXml($xml);

expect($component->getDate())->to->equal($date);
expect($component->getTime())->to->equal($time);
expect($component->getMessage())->to->equal($message);
expect($component->getCode())->to->equal($code);
expect($component->getType())->to->equal($type);
$message = $this->getContainer()->get('component.status')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
Expand Down
26 changes: 4 additions & 22 deletions tests/src/Messages/Components/TargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,16 @@ public function testValidation()
}

/**
* Test parsing.
*
* @param string $xml
* @param array $targetProperties
* @param array $addressProperties
* @param array $contactProperties
* @param array $expressions
*
* @dataProvider parserProvider
*/
public function testParsing($xml, $targetProperties, $addressProperties, $contactProperties)
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Components\Target $target */
$target = $this->getContainer()->get('component.target')->withXml($xml);

foreach ($targetProperties as $method => $value) {
expect($target->$method())->to->equal($value);
}
$returnAddress = $target->getReturnAddresses()[0];
foreach ($addressProperties as $method => $value) {
expect($returnAddress->$method())->to->equal($value);
}
expect(count($target->getContacts()))->to->equal(1);
$contact = $target->getContacts()[0];
foreach ($contactProperties as $method => $value) {
expect($contact->$method())->to->equal($value);
}
$message = $this->getContainer()->get('component.target')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
* @return mixed
*/
Expand Down
5 changes: 1 addition & 4 deletions tests/src/Messages/Notifications/StatusUpdatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public function testRender()
*/
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Notifications\TranslationReceived $message */
$message = $this->getContainer()
->get('notification.status_updated')
->withXml($xml);
$message = $this->getContainer()->get('notification.status_updated')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/src/Messages/Notifications/TranslationReceivedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public function testRender()
*/
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Notifications\TranslationReceived $message */
$message = $this->getContainer()
->get('notification.translation_received')
->withXml($xml);
$message = $this->getContainer()->get('notification.translation_received')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/src/Messages/Responses/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class StatusTest extends AbstractTest
*/
public function testWithXml($xml, $expressions)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()
->get('response.status')
->withXml($xml);
$message = $this->getContainer()->get('response.status')->withXml($xml);
$this->assertExpressions($expressions, ['message' => $message]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
-
-
xml:
<documentReference lgCode="en" format="HTML" type="REF" action="UPDATE">
<documentReferenceName>Filename</documentReferenceName>
<documentReferencePath>path</documentReferencePath>
<documentReferenceSize>10kB</documentReferenceSize>
<documentReferenceRemark>Remark</documentReferenceRemark>
<documentReferenceFile>File</documentReferenceFile>
</documentReference>
- getLanguage : "en"
getFormat : "HTML"
getType : "REF"
getAction : "UPDATE"
getName : "Filename"
getPath : "path"
getSize : "10kB"
getRemark : "Remark"
getFile : "File"

expressions:
- message.getLanguage() == "en"
- message.getFormat() == "HTML"
- message.getType() == "REF"
- message.getAction() == "UPDATE"
- message.getName() == "Filename"
- message.getPath() == "path"
- message.getSize() == "10kB"
- message.getRemark() == "Remark"
- message.getFile() == "File"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-
xml:
<retour type="webService" action="INSERT">
<retourUser>Username</retourUser>
<retourPassword>Password</retourPassword>
<retourAddress>Url</retourAddress>
<retourPath>Path</retourPath>
<retourRemark>Remark</retourRemark>
</retour>

expressions:
- message.getType() == "webService"
- message.getAction() == "INSERT"
- message.getUser() == "Username"
- message.getPassword() == "Password"
- message.getAddress() == "Url"
- message.getPath() == "Path"
- message.getRemark() == "Remark"
16 changes: 0 additions & 16 deletions tests/src/fixtures/factories/with-xml/components/returnAddress.yml

This file was deleted.

37 changes: 18 additions & 19 deletions tests/src/fixtures/factories/with-xml/components/source.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-
-
xml:
<documentSource channel="POETRY" format="HTML" deadline="11/07/2007" statusDeadline="PUBLIC" marked="No" legiswrite="Yes" trackChanges="No">
<documentSourceName>Name</documentSourceName>
<documentSourcePath>Path</documentSourcePath>
Expand All @@ -12,21 +12,20 @@
<documentSourceSize>10kB</documentSourceSize>
<documentSourceFile>File</documentSourceFile>
</documentSource>
- getChannel: "POETRY"
getFormat: "HTML"
getDeadline: "11/07/2007"
getDeadlineStatus: "PUBLIC"
getConfidential: "No"
getLegiswriteFormat: "Yes"
getTrackChanges: "No"
getName: "Name"
getPath: "Path"
getSourceLanguages:
-
getCode: 'en'
getPages: '1'
-
getCode: 'fr'
getPages: '2'
getSize: "10kB"
getFile: "File"

expressions:
- message.getChannel() == "POETRY"
- message.getFormat() == "HTML"
- message.getDeadline() == "11/07/2007"
- message.getDeadlineStatus() == "PUBLIC"
- message.getConfidential() == "No"
- message.getLegiswriteFormat() == "Yes"
- message.getTrackChanges() == "No"
- message.getName() == "Name"
- message.getPath() == "Path"
- message.getSourceLanguages()[0].getCode() == 'en'
- message.getSourceLanguages()[0].getPages() == '1'
- message.getSourceLanguages()[1].getCode() == 'fr'
- message.getSourceLanguages()[1].getPages() == '2'
- message.getSize() == "10kB"
- message.getFile() == "File"
28 changes: 16 additions & 12 deletions tests/src/fixtures/factories/with-xml/components/status.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
-
-
xml:
<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>
- "15/01/2017"
- "12:30:00"
- "OK"
- "0"
- "request"

expressions:
- message.getDate() == "15/01/2017"
- message.getTime() == "12:30:00"
- message.getMessage() == "OK"
- message.getCode() == "0"
- message.getType() == "request"

-
-
xml:
<status type="request">
<statusTime format="hh:mm:ss">12:30:00</statusTime>
<statusMessage>OK</statusMessage>
</status>
- null
- "12:30:00"
- "OK"
- null
- "request"

expressions:
- message.getDate() == null
- message.getTime() == "12:30:00"
- message.getMessage() == "OK"
- message.getCode() == null
- message.getType() == "request"

Loading

0 comments on commit 21a7066

Please sign in to comment.