Skip to content

Commit

Permalink
added tests for proprietary amount (with real data received from bank…
Browse files Browse the repository at this point in the history
…) and fixed the null issue
  • Loading branch information
Marko Petrovic committed Mar 14, 2023
1 parent 81c9f2b commit f495a7f
Show file tree
Hide file tree
Showing 19 changed files with 453 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/DTO/Creditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Creditor implements RelatedPartyTypeInterface
{
private ?Address $address = null;
private ?string $orgId;
private ?string $orgId = null;

public function __construct(private ?string $name)
{
Expand All @@ -28,7 +28,7 @@ public function getName(): ?string
return $this->name;
}

public function setOrgId(?string $orgId): void
public function setOrgId(string $orgId): void
{
$this->orgId = $orgId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DTO/Debtor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Debtor implements RelatedPartyTypeInterface
{
private ?Address $address = null;
private ?string $orgId;
private ?string $orgId = null;

public function __construct(private ?string $name)
{
Expand All @@ -28,7 +28,7 @@ public function getName(): ?string
return $this->name;
}

public function setOrgId(?string $orgId): void
public function setOrgId(string $orgId): void
{
$this->orgId = $orgId;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Decoder/EntryTransactionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ protected function addRelatedParty(DTO\EntryTransactionDetail $detail, SimpleXML
$xmlRelatedPartyName = (isset($xmlPartyDetail->Nm)) ? (string) $xmlPartyDetail->Nm : null;
$relatedPartyType = new $relatedPartyTypeClass($xmlRelatedPartyName);
$orgId = $xmlRelatedPartyType?->Id?->OrgId?->Othr?->Id;

$relatedPartyType->setOrgId((string)$orgId);
if (isset($orgId)) {
$relatedPartyType->setOrgId((string) $orgId);
}
if (isset($xmlPartyDetail->PstlAdr)) {
$relatedPartyType->setAddress(DTOFactory\Address::createFromXml($xmlPartyDetail->PstlAdr));
}
Expand Down
276 changes: 275 additions & 1 deletion test/Unit/Camt054/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ public function testEntries(): void
public function testTransactionDetails(): void
{
$messages = [
$this->getV2Message(),
$this->getV4Message(),
$this->getV8Message(),
];

// this is because V4 and V8 don't support the structure with proprietary amount
$this->testV2Message();

foreach ($messages as $message) {
$notifications = $message->getRecords();

Expand Down Expand Up @@ -376,4 +378,276 @@ public function testTransactionDetails(): void
}
}
}

public function testV2Message(): void
{
$message = $this->getV2Message();

$notifications = $message->getRecords();

self::assertCount(1, $notifications);
foreach ($notifications as $notification) {
$entries = $notification->getEntries();

self::assertCount(1, $entries);
foreach ($entries as $entry) {
$transactionDetails = $entry->getTransactionDetails();
self::assertCount(4, $transactionDetails);
foreach ($transactionDetails as $index => $transactionDetail) {
switch ($index) {
case 0:
// Legacy : The first message comes from unstructured block
self::assertEquals(
'Unstructured Remittance Information V1',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// Only one structured data block
self::assertEquals(
'Unstructured Remittance Information V1',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlock()
->getMessage()
);

// Check structured and unstructured blocks
self::assertEquals(
'ISR ref number V1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getRef()
);

self::assertEquals(
'ISR Reference',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getProprietary()
);

self::assertNull(
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getCode()
);

self::assertEquals(
'Additional Remittance Information V1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getAdditionalRemittanceInformation()
);

break;
case 1:
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// Only one structured data block
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlock()
->getMessage()
);

// Check structured and unstructured blocks
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getRef()
);

self::assertEquals(
null,
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getProprietary()
);

self::assertEquals(
'SCOR',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getCode()
);

self::assertEquals(
null,
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getAdditionalRemittanceInformation()
);
break;
case 2:

// Legacy : ref number from the structured information
// because the unstructured block is not present
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// No unstructured block
self::assertCount(
0,
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlocks()
);

// Check structured and unstructured blocks
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getRef()
);

self::assertEquals(
'ISR Reference',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getProprietary()
);

self::assertNull(
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getCode()
);

self::assertEquals(
'Additional Remittance Information V2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getAdditionalRemittanceInformation()
);

break;
case 3:
// Legacy : ref number from the first unstructured block
self::assertEquals(
'Unstructured Remittance Information V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// First unstructured block
self::assertEquals(
'Unstructured Remittance Information V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlocks()[0]
->getMessage()
);

// Second unstructured block
self::assertEquals(
'Unstructured Remittance Information V3 block 2',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlocks()[1]
->getMessage()
);

// Ref number from the first structured block
self::assertEquals(
'Ref number V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[0]
->getCreditorReferenceInformation()
->getRef()
);

// Ref number from the second structured block
self::assertEquals(
'Ref number V3 block 2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[1]
->getCreditorReferenceInformation()
->getRef()
);

// Code from the first structured block
self::assertEquals(
'SCOR',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[0]
->getCreditorReferenceInformation()
->getCode()
);

// Code from the second structured block
self::assertEquals(
'SCOR',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[1]
->getCreditorReferenceInformation()
->getCode()
);

// Additional remittance information from the first structured block
self::assertEquals(
'Additional Remittance Information V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[0]
->getAdditionalRemittanceInformation()
);

// Additional remittance information from the second structured block
self::assertEquals(
'Additional Remittance Information V3 block 2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[1]
->getAdditionalRemittanceInformation()
);

break;
default:
break;
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion test/data/camt052.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"getTownName": null
},
"getName": "NAME NAME",
"getOrgId": ""
"getOrgId": null
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion test/data/camt052.v2.other-account.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"getTownName": null
},
"getName": "NAME NAME",
"getOrgId": ""
"getOrgId": null
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions test/data/camt052.v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
"getAddress": null,
"getName": "UNIFITS GmbH",
"getOrgId": ""
"getOrgId": null
}
},
{
Expand Down Expand Up @@ -220,7 +220,7 @@
"getTownName": "Example Creditor Town 4 - V1"
},
"getName": "Example Creditor 4 - V1",
"getOrgId": ""
"getOrgId": null
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions test/data/camt052.v6.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
"getAddress": null,
"getName": "UNIFITS GmbH",
"getOrgId": ""
"getOrgId": null
}
},
{
Expand Down Expand Up @@ -220,7 +220,7 @@
"getTownName": "Example Creditor Town 6 - V1"
},
"getName": "Example Creditor 6 - V1",
"getOrgId": ""
"getOrgId": null
}
}
],
Expand Down
Loading

0 comments on commit f495a7f

Please sign in to comment.