From 66527c836120028555d6b09cbd4326e1d54b25e8 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Tue, 7 Nov 2017 12:00:55 +0100 Subject: [PATCH] Issue #62: Port component tests to expression language. --- tests/src/Messages/Components/ContactTest.php | 19 ++++------ tests/src/Messages/Components/DetailsTest.php | 17 ++++----- .../Messages/Components/IdentifierTest.php | 25 ++++--------- .../factories/with-xml/components/contact.yml | 20 ++++++----- .../factories/with-xml/components/details.yml | 35 ++++++++++--------- .../with-xml/components/identifier.yml | 32 +++++++++-------- 6 files changed, 69 insertions(+), 79 deletions(-) diff --git a/tests/src/Messages/Components/ContactTest.php b/tests/src/Messages/Components/ContactTest.php index 7d7e9b4..a2fc915 100644 --- a/tests/src/Messages/Components/ContactTest.php +++ b/tests/src/Messages/Components/ContactTest.php @@ -39,23 +39,18 @@ public function testValidation() } /** - * Test parsing. - * * @param string $xml - * @param string $type - * @param string $nickname - * @param string $email + * @param array $expressions * * @dataProvider parserProvider */ - public function testParsing($xml, $type, $nickname, $email) + public function testWithXml($xml, $expressions) { - /** @var \EC\Poetry\Messages\Components\Contact $component */ - $component = $this->getContainer()->get('component.contact')->withXml($xml); - - expect($component->getType())->to->equal($type); - expect($component->getNickname())->to->equal($nickname); - expect($component->getEmail())->to->equal($email); + /** @var \EC\Poetry\Messages\Responses\Status $message */ + $message = $this->getContainer() + ->get('component.contact') + ->withXml($xml); + $this->assertExpressions($expressions, ['message' => $message]); } /** diff --git a/tests/src/Messages/Components/DetailsTest.php b/tests/src/Messages/Components/DetailsTest.php index 51f36e9..f289761 100644 --- a/tests/src/Messages/Components/DetailsTest.php +++ b/tests/src/Messages/Components/DetailsTest.php @@ -34,21 +34,18 @@ 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\Details $component */ - $component = $this->getContainer()->get('component.details')->withXml($xml); - - foreach ($fixtures as $method => $value) { - expect($component->$method())->to->equal($value); - } + /** @var \EC\Poetry\Messages\Responses\Status $message */ + $message = $this->getContainer() + ->get('component.details') + ->withXml($xml); + $this->assertExpressions($expressions, ['message' => $message]); } /** diff --git a/tests/src/Messages/Components/IdentifierTest.php b/tests/src/Messages/Components/IdentifierTest.php index 9f9c18c..b138b25 100644 --- a/tests/src/Messages/Components/IdentifierTest.php +++ b/tests/src/Messages/Components/IdentifierTest.php @@ -40,29 +40,18 @@ public function testValidation() } /** - * Test parsing. - * * @param string $xml - * @param string $code - * @param string $year - * @param string $number - * @param string $version - * @param string $part - * @param string $product + * @param array $expressions * * @dataProvider parserProvider */ - public function testParsing($xml, $code, $year, $number, $version, $part, $product) + public function testWithXml($xml, $expressions) { - /** @var \EC\Poetry\Messages\Components\Identifier $component */ - $component = $this->getContainer()->get('component.identifier')->withXml($xml); - - expect($component->getCode())->to->equal($code); - expect($component->getYear())->to->equal($year); - expect($component->getNumber())->to->equal($number); - expect($component->getVersion())->to->equal($version); - expect($component->getPart())->to->equal($part); - expect($component->getProduct())->to->equal($product); + /** @var \EC\Poetry\Messages\Responses\Status $message */ + $message = $this->getContainer() + ->get('component.identifier') + ->withXml($xml); + $this->assertExpressions($expressions, ['message' => $message]); } /** diff --git a/tests/src/fixtures/factories/with-xml/components/contact.yml b/tests/src/fixtures/factories/with-xml/components/contact.yml index fd23dd5..a223792 100644 --- a/tests/src/fixtures/factories/with-xml/components/contact.yml +++ b/tests/src/fixtures/factories/with-xml/components/contact.yml @@ -1,19 +1,23 @@ - - - + xml: Username user@mail.com - - "Secretaire" - - "Username" - - "user@mail.com" + + expressions: + - message.getType() == "Secretaire" + - message.getNickname() == "Username" + - message.getEmail() == "user@mail.com" - - - + xml: Username - - "Secretaire" - - "Username" - - null + + expressions: + - message.getType() == "Secretaire" + - message.getNickname() == "Username" + - message.getEmail() == null diff --git a/tests/src/fixtures/factories/with-xml/components/details.yml b/tests/src/fixtures/factories/with-xml/components/details.yml index 2f0bd1a..9940b75 100644 --- a/tests/src/fixtures/factories/with-xml/components/details.yml +++ b/tests/src/fixtures/factories/with-xml/components/details.yml @@ -1,5 +1,5 @@ - - - + xml: clientId applicationId @@ -18,20 +18,21 @@ Note STS - - getClientId : "clientId" - getApplicationId : "applicationId" - getAuthor : "DIGIT" - getRequester : "DGCOMM" - getTitle : "Title" - getRemark : "Remark" - getType : "INTER" - getDestination : "AUTRE" - getProcedure : "NEANT" - getDelay : "11/12/2007" - getRequestDate : "11/12/2007" - getStatus : "Ready" - getInterServices : "Yes" - getInterInstitution : "Yes" - getReferenceFilesRemark : "Note" - getWorkflowCode : "STS" + expressions: + - message.getClientId() == "clientId" + - message.getApplicationId() == "applicationId" + - message.getAuthor() == "DIGIT" + - message.getRequester() == "DGCOMM" + - message.getTitle() == "Title" + - message.getRemark() == "Remark" + - message.getType() == "INTER" + - message.getDestination() == "AUTRE" + - message.getProcedure() == "NEANT" + - message.getDelay() == "11/12/2007" + - message.getRequestDate() == "11/12/2007" + - message.getStatus() == "Ready" + - message.getInterServices() == "Yes" + - message.getInterInstitution() == "Yes" + - message.getReferenceFilesRemark() == "Note" + - message.getWorkflowCode() == "STS" diff --git a/tests/src/fixtures/factories/with-xml/components/identifier.yml b/tests/src/fixtures/factories/with-xml/components/identifier.yml index bb21de1..dc34091 100644 --- a/tests/src/fixtures/factories/with-xml/components/identifier.yml +++ b/tests/src/fixtures/factories/with-xml/components/identifier.yml @@ -1,5 +1,5 @@ - - - + xml: DGT 2017 @@ -8,25 +8,29 @@ 00 ABC - - "DGT" - - "2017" - - "0001" - - "01" - - "00" - - "ABC" + + expressions: + - message.getCode() == "DGT" + - message.getYear() == "2017" + - message.getNumber() == "0001" + - message.getVersion() == "01" + - message.getPart() == "00" + - message.getProduct() == "ABC" + - message.getFormattedIdentifier() == "DGT/2017/0001/01/00/ABC" - - - + xml: DGT 01 00 ABC - - "DGT" - - null - - null - - "01" - - "00" - - "ABC" + expressions: + - message.getCode() == "DGT" + - message.getYear() == null + - message.getNumber() == null + - message.getVersion() == "01" + - message.getPart() == "00" + - message.getProduct() == "ABC"