Skip to content

Commit

Permalink
Issue #62: Fix withArray() tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Nov 7, 2017
1 parent 21a7066 commit aa7ec9b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 163 deletions.
19 changes: 2 additions & 17 deletions tests/src/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,9 @@ protected function getLogs()
}

/**
* Assert property hash.
*
* @param $component
* @param $properties
* @param array $expressions
* @param $options
*/
protected function assertProperties($component, $properties)
{
foreach ($properties as $getProperty => $value) {
if ($this->isComponentCollection($value)) {
foreach ($value as $i => $property) {
$this->assertProperties($component->$getProperty()[$i], $property);
}
} else {
expect($component->$getProperty())->to->equal($value);
}
}
}

protected function assertExpressions(array $expressions, $options)
{
$language = new ExpressionLanguage();
Expand Down
20 changes: 4 additions & 16 deletions tests/src/Messages/Components/DetailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,14 @@ public function testWithXml($xml, $expressions)

/**
* @param array $array
* @param array $expected
* @param array $expressions
*
* @dataProvider withArrayProvider
*/
public function testWithArray(array $array, array $expected)
public function testWithArray(array $array, array $expressions)
{
$component = new Details();
foreach ($array as $name => $value) {
$component[$name] = $value;
}

foreach ($expected as $method => $value) {
expect($component->$method())->to->equal($value);
}

$component = new Details();
$component->withArray($array);
foreach ($expected as $method => $value) {
expect($component->$method())->to->equal($value);
}
$message = $this->getContainer()->get('component.details')->withArray($array);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
Expand Down
21 changes: 4 additions & 17 deletions tests/src/Messages/Requests/CreateReviewRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public function testRender()

/**
* @param array $array
* @param array $expected
* @param array $expressions
*
* @dataProvider withArrayProvider
*/
public function testWithArray(array $array, array $expected)
public function testWithArray(array $array, array $expressions)
{
$poetry = new Poetry([
'identifier.code' => 'STSI',
Expand All @@ -102,21 +102,8 @@ public function testWithArray(array $array, array $expected)
'notification.password' => 'MY-TEST-PASSWORD',
'client.wsdl' => 'https://example.com/callback/wsdl/PoetryIntegration.wsdl',
]);
$component = $poetry->get('request.create_review_request');
$component->withArray($array);

foreach ($expected as $getComponent => $properties) {
if ($this->isComponentCollection($properties)) {
foreach ($properties as $i => $property) {
$this->assertProperties($component->$getComponent()[$i], $property);
}
} else {
$this->assertProperties($component->$getComponent(), $properties);
}
}

$violations = $this->getContainer()->getValidator()->validate($component);
expect($this->getViolations($violations))->to->be->empty();
$message = $poetry->get('request.create_review_request')->withArray($array);
$this->assertExpressions($expressions, ['message' => $message]);
}

/**
Expand Down
35 changes: 18 additions & 17 deletions tests/src/fixtures/factories/with-array/components/details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
inter_institution: "Yes"
reference_files_remark: "Note"
workflowCode: "STS"
expected:
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"
172 changes: 76 additions & 96 deletions tests/src/fixtures/factories/with-array/create-review-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
array:
details:
client_id: 'Job ID 3999'
title: 'NE-CMS: Erasmus+ - Erasmus Mundus Joint Master Degrees'
title: 'NE-CMS Erasmus+ - Erasmus Mundus Joint Master Degrees'
author: 'IE/CE/EAC'
responsible: 'EAC'
requester: 'IE/CE/EAC/C/4'
Expand Down Expand Up @@ -40,59 +40,49 @@
format: 'HTML'
language: 'EN'
delay: '12/09/2017'
expected:
getIdentifier:
getCode: 'STSI'
getYear: '2017'
getNumber: '40017'
getVersion: '0'
getPart: '11'
getDetails:
getClientId: 'Job ID 3999'
getTitle: 'NE-CMS: Erasmus+ - Erasmus Mundus Joint Master Degrees'
getAuthor: 'IE/CE/EAC'
getResponsible: 'EAC'
getRequester: 'IE/CE/EAC/C/4'
getApplicationId: 'FPFIS'
getDelay: '12/09/2017'
getReferenceFilesRemark: 'https://ec.europa.eu/programmes/erasmus-plus/opportunities-for-individuals/staff-teaching/erasmus-mundus_en'
getProcedure: 'NEANT'
getDestination: 'PUBLIC'
getType: 'INTER'
getReturnAddress:
getAction: 'UPDATE'
getType: 'webService'
getUser: 'MY-TEST-USER'
getPassword: 'MY-TEST-PASSWORD'
getAddress: 'https://example.com/callback/wsdl/PoetryIntegration.wsdl'
getPath: 'handle'
getSource:
getFormat: 'HTML'
getName: 'content.html'
getFile: 'BASE64ENCODEDFILECONTENT'
getSourceLanguages:
-
getCode: 'EN'
getPages: 1
getContacts:
-
getType: 'auteur'
getNickname: 'john'
-
getType: 'secretaire'
getNickname: 'john'
-
getType: 'contact'
getNickname: 'john'
-
getType: 'responsable'
getNickname: 'mark'

expressions:
- message.getIdentifier().getCode() == 'STSI'
- message.getIdentifier().getYear() == '2017'
- message.getIdentifier().getNumber() == '40017'
- message.getIdentifier().getVersion() == '0'
- message.getIdentifier().getPart() == '11'
- message.getDetails().getClientId() == 'Job ID 3999'
- message.getDetails().getTitle() == 'NE-CMS Erasmus+ - Erasmus Mundus Joint Master Degrees'
- message.getDetails().getAuthor() == 'IE/CE/EAC'
- message.getDetails().getResponsible() == 'EAC'
- message.getDetails().getRequester() == 'IE/CE/EAC/C/4'
- message.getDetails().getApplicationId() == 'FPFIS'
- message.getDetails().getDelay() == '12/09/2017'
- message.getDetails().getReferenceFilesRemark() == 'https://ec.europa.eu/programmes/erasmus-plus/opportunities-for-individuals/staff-teaching/erasmus-mundus_en'
- message.getDetails().getProcedure() == 'NEANT'
- message.getDetails().getDestination() == 'PUBLIC'
- message.getDetails().getType() == 'INTER'
- message.getReturnAddress().getAction() == 'UPDATE'
- message.getReturnAddress().getType() == 'webService'
- message.getReturnAddress().getUser() == 'MY-TEST-USER'
- message.getReturnAddress().getPassword() == 'MY-TEST-PASSWORD'
- message.getReturnAddress().getAddress() == 'https://example.com/callback/wsdl/PoetryIntegration.wsdl'
- message.getReturnAddress().getPath() == 'handle'
- message.getSource().getFormat() == 'HTML'
- message.getSource().getName() == 'content.html'
- message.getSource().getFile() == 'BASE64ENCODEDFILECONTENT'
- message.getSource().getSourceLanguages()[0].getCode() == 'EN'
- message.getSource().getSourceLanguages()[0].getPages() == 1
- message.getContacts()[0].getType() == 'auteur'
- message.getContacts()[0].getNickname() == 'john'
- message.getContacts()[1].getType() == 'secretaire'
- message.getContacts()[1].getNickname() == 'john'
- message.getContacts()[2].getType() == 'contact'
- message.getContacts()[2].getNickname() == 'john'
- message.getContacts()[3].getType() == 'responsable'
- message.getContacts()[3].getNickname() == 'mark'

-
array:
details:
client_id: 'Job ID 3999'
title: 'NE-CMS: Erasmus+ - Erasmus Mundus Joint Master Degrees'
title: 'NE-CMS Erasmus+ - Erasmus Mundus Joint Master Degrees'
author: 'IE/CE/EAC'
responsible: 'EAC'
requester: 'IE/CE/EAC/C/4'
Expand Down Expand Up @@ -137,50 +127,40 @@
password: 'MY-TEST-PASSWORD-2'
address: 'https://example.com/callback/wsdl/PoetryIntegration-2.wsdl'
path: 'TestReturnPath'
expected:
getIdentifier:
getCode: 'STSI'
getYear: '2017'
getNumber: '40017'
getVersion: '0'
getPart: '11'
getDetails:
getClientId: 'Job ID 3999'
getTitle: 'NE-CMS: Erasmus+ - Erasmus Mundus Joint Master Degrees'
getAuthor: 'IE/CE/EAC'
getResponsible: 'EAC'
getRequester: 'IE/CE/EAC/C/4'
getApplicationId: 'FPFIS'
getDelay: '12/09/2017'
getReferenceFilesRemark: 'https://ec.europa.eu/programmes/erasmus-plus/opportunities-for-individuals/staff-teaching/erasmus-mundus_en'
getProcedure: 'NEANT'
getDestination: 'PUBLIC'
getType: 'INTER'
getReturnAddress:
getAction: 'UPDATE'
getType: 'webService'
getUser: 'MY-TEST-USER-2'
getPassword: 'MY-TEST-PASSWORD-2'
getAddress: 'https://example.com/callback/wsdl/PoetryIntegration-2.wsdl'
getPath: 'TestReturnPath'
getSource:
getFormat: 'HTML'
getName: 'content.html'
getFile: 'BASE64ENCODEDFILECONTENT'
getSourceLanguages:
-
getCode: 'EN'
getPages: 1
getContacts:
-
getType: 'auteur'
getNickname: 'john'
-
getType: 'secretaire'
getNickname: 'john'
-
getType: 'contact'
getNickname: 'john'
-
getType: 'responsable'
getNickname: 'mark'

expressions:
- message.getIdentifier().getCode() == 'STSI'
- message.getIdentifier().getYear() == '2017'
- message.getIdentifier().getNumber() == '40017'
- message.getIdentifier().getVersion() == '0'
- message.getIdentifier().getPart() == '11'
- message.getDetails().getClientId() == 'Job ID 3999'
- message.getDetails().getTitle() == 'NE-CMS Erasmus+ - Erasmus Mundus Joint Master Degrees'
- message.getDetails().getAuthor() == 'IE/CE/EAC'
- message.getDetails().getResponsible() == 'EAC'
- message.getDetails().getRequester() == 'IE/CE/EAC/C/4'
- message.getDetails().getApplicationId() == 'FPFIS'
- message.getDetails().getDelay() == '12/09/2017'
- message.getDetails().getReferenceFilesRemark() == 'https://ec.europa.eu/programmes/erasmus-plus/opportunities-for-individuals/staff-teaching/erasmus-mundus_en'
- message.getDetails().getProcedure() == 'NEANT'
- message.getDetails().getDestination() == 'PUBLIC'
- message.getDetails().getType() == 'INTER'
- message.getReturnAddress().getAction() == 'UPDATE'
- message.getReturnAddress().getType() == 'webService'
- message.getReturnAddress().getUser() == 'MY-TEST-USER-2'
- message.getReturnAddress().getPassword() == 'MY-TEST-PASSWORD-2'
- message.getReturnAddress().getAddress() == 'https://example.com/callback/wsdl/PoetryIntegration-2.wsdl'
- message.getReturnAddress().getPath() == 'TestReturnPath'
- message.getSource().getFormat() == 'HTML'
- message.getSource().getName() == 'content.html'
- message.getSource().getFile() == 'BASE64ENCODEDFILECONTENT'
- message.getSource().getSourceLanguages()[0].getCode() == 'EN'
- message.getSource().getSourceLanguages()[0].getPages() == 1
- message.getContacts()[0].getType() == 'auteur'
- message.getContacts()[0].getNickname() == 'john'
- message.getContacts()[1].getType() == 'secretaire'
- message.getContacts()[1].getNickname() == 'john'
- message.getContacts()[2].getType() == 'contact'
- message.getContacts()[2].getNickname() == 'john'
- message.getContacts()[3].getType() == 'responsable'
- message.getContacts()[3].getNickname() == 'mark'

0 comments on commit aa7ec9b

Please sign in to comment.