From 4280e022f783fa55f5a0890b5e7bd7b8a8afbd0e Mon Sep 17 00:00:00 2001 From: eric-reichenbach <8860625+eric-reichenbach@users.noreply.github.com> Date: Tue, 19 Oct 2021 06:39:33 +0200 Subject: [PATCH 1/2] Qr bill integration (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add BankCredit specializations for QR with reference and creditor reference * Add comments Co-authored-by: Sébastien Despont --- .gitignore | 4 +- .../PaymentInformation/PaymentInformation.php | 2 +- ...ankCreditTransferWithCreditorReference.php | 86 +++++++++++++++++++ .../BankCreditTransferWithQRR.php | 85 ++++++++++++++++++ .../Message/CustomerCreditTransferTest.php | 47 +++++++++- 5 files changed, 218 insertions(+), 6 deletions(-) create mode 100644 src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php create mode 100644 src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php diff --git a/.gitignore b/.gitignore index 0f401cd..bdae0e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ .php_cs .php_cs.cache - +*.phpunit.result.cache phpunit.xml - +/.idea/ composer.lock /vendor/ /.idea diff --git a/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php b/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php index 1d09748..2bea818 100644 --- a/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php +++ b/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php @@ -21,7 +21,7 @@ class PaymentInformation protected $id; /** - * @var array + * @var CreditTransfer[] */ protected $transactions; diff --git a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php new file mode 100644 index 0000000..747df9d --- /dev/null +++ b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php @@ -0,0 +1,86 @@ +creditorReference = $cleanedCreditorReference; + + if (preg_match('/^CH[0-9]{2}3/', $creditorIBAN->normalize())) { + throw new InvalidArgumentException('The IBAN must not be a QR-IBAN'); + } + + parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress, $creditorIBAN, $creditorAgent); + } + + /** + * @param DOMDocument $doc + * @param DOMElement $transaction + */ + protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) + { + $remittanceInformation = $doc->createElement('RmtInf'); + + $structured = $doc->createElement('Strd'); + $remittanceInformation->appendChild($structured); + + $creditorReferenceInformation = $doc->createElement('CdtrRefInf'); + $structured->appendChild($creditorReferenceInformation); + + $codeOrProperty = $doc->createElement('CdOrPrtry'); + $codeOrProperty->appendChild($doc->createElement('Cd', 'SCOR')); + $type = $doc->createElement('Tp'); + $type->appendChild($codeOrProperty); + + $creditorReferenceInformation->appendChild($type); + $creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); + + if (!empty($this->remittanceInformation)) { + $structured->appendChild($doc->createElement('AddtlRmtInf', $this->remittanceInformation)); + } + + $transaction->appendChild($remittanceInformation); + } +} diff --git a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php new file mode 100644 index 0000000..2fe3260 --- /dev/null +++ b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php @@ -0,0 +1,85 @@ +creditorReference = $creditorReference; + + if (!preg_match('/^CH[0-9]{2}3/', $creditorIBAN->normalize())) { + throw new InvalidArgumentException('The IBAN must be a QR-IBAN'); + } + + parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress, $creditorIBAN, $creditorAgent); + } + + /** + * @param DOMDocument $doc + * @param DOMElement $transaction + */ + protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) + { + $remittanceInformation = $doc->createElement('RmtInf'); + + $structured = $doc->createElement('Strd'); + $remittanceInformation->appendChild($structured); + + $creditorReferenceInformation = $doc->createElement('CdtrRefInf'); + $structured->appendChild($creditorReferenceInformation); + + $codeOrProperty = $doc->createElement('CdOrPrtry'); + $codeOrProperty->appendChild($doc->createElement('Prtry', 'QRR')); + $type = $doc->createElement('Tp'); + $type->appendChild($codeOrProperty); + + $creditorReferenceInformation->appendChild($type); + $creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); + + if (!empty($this->remittanceInformation)) { + $structured->appendChild($doc->createElement('AddtlRmtInf', $this->remittanceInformation)); + } + + $transaction->appendChild($remittanceInformation); + } +} diff --git a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php index 0a11b5f..24cdf97 100644 --- a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php @@ -17,6 +17,8 @@ use Z38\SwissPayment\StructuredPostalAddress; use Z38\SwissPayment\Tests\TestCase; use Z38\SwissPayment\TransactionInformation\BankCreditTransfer; +use Z38\SwissPayment\TransactionInformation\BankCreditTransferWithCreditorReference; +use Z38\SwissPayment\TransactionInformation\BankCreditTransferWithQRR; use Z38\SwissPayment\TransactionInformation\ForeignCreditTransfer; use Z38\SwissPayment\TransactionInformation\IS1CreditTransfer; use Z38\SwissPayment\TransactionInformation\IS2CreditTransfer; @@ -51,6 +53,7 @@ protected function buildMessage() new IBAN('CH51 0022 5225 9529 1301 C'), new BIC('UBSWCHZH80A') ); + $transaction->setRemittanceInformation("Test Remittance"); $payment->addTransaction($transaction); $transaction = new IS1CreditTransfer( @@ -73,6 +76,7 @@ protected function buildMessage() 'Musterbank AG', new PostalAccount('80-151-4') ); + $transaction->setRemittanceInformation("Test Remittance"); $payment->addTransaction($transaction); $iban = new IBAN('CH51 0022 5225 9529 1301 C'); @@ -85,6 +89,7 @@ protected function buildMessage() $iban, IID::fromIBAN($iban) ); + $transaction->setRemittanceInformation("Test Remittance"); $transaction->setPurpose(new PurposeCode('AIRB')); $payment->addTransaction($transaction); @@ -207,6 +212,42 @@ protected function buildMessage() new StructuredPostalAddress('Dorfstrasse', '17', '9911', 'Musterwald'), new PostalAccount('60-9-9') ); + $transaction->setRemittanceInformation("Test Remittance"); + $payment->addTransaction($transaction); + + $payment = new PaymentInformation( + 'payment-050', + 'InnoMuster AG', + new BIC('ZKBKCHZZ80A'), + new IBAN('CH6600700110000204481') + ); + $message->addPayment($payment); + + $qrIban = new IBAN('CH44 3199 9123 0008 8901 2'); + $transaction = new BankCreditTransferWithQRR( + 'instr-050', + 'e2e-050', + new Money\CHF(130000), // CHF 1300.00 + 'Muster Transport AG', + new StructuredPostalAddress('Wiesenweg', '14b', '8058', 'Zürich-Flughafen'), + $qrIban, + IID::fromIBAN($qrIban), + '210000000003139471430009017' + ); + $transaction->setRemittanceInformation("Test Remittance"); + $payment->addTransaction($transaction); + + $transaction = new BankCreditTransferWithCreditorReference( + 'instr-050', + 'e2e-050', + new Money\CHF(130000), // CHF 1300.00 + 'Muster Transport AG', + new StructuredPostalAddress('Wiesenweg', '14b', '8058', 'Zürich-Flughafen'), + $iban, + IID::fromIBAN($iban), + 'RF 72 0191 2301 0040 5JSH 0438' + ); + $transaction->setRemittanceInformation("Test Remittance"); $payment->addTransaction($transaction); return $message; @@ -222,10 +263,10 @@ public function testGroupHeader() $xpath->registerNamespace('pain001', self::SCHEMA); $nbOfTxs = $xpath->evaluate('string(//pain001:GrpHdr/pain001:NbOfTxs)'); - $this->assertEquals('12', $nbOfTxs); + $this->assertEquals('14', $nbOfTxs); $ctrlSum = $xpath->evaluate('string(//pain001:GrpHdr/pain001:CtrlSum)'); - $this->assertEquals('4210.001', $ctrlSum); + $this->assertEquals('6810.001', $ctrlSum); } public function testSchemaValidation() @@ -250,6 +291,6 @@ public function testGetPaymentCount() { $message = $this->buildMessage(); - $this->assertSame(5, $message->getPaymentCount()); + $this->assertSame(6, $message->getPaymentCount()); } } From c85bb226b83553e6593172eb698077f8d3360c99 Mon Sep 17 00:00:00 2001 From: ch2877 <92625296+ch2877@users.noreply.github.com> Date: Tue, 19 Oct 2021 17:36:39 +0200 Subject: [PATCH 2/2] Bump to PHP 8 (#3) * Bump to PHP 8 * Drop everything below PHP 7.2 * Update PHPUnit --- .github/workflows/tests.yml | 2 +- CHANGELOG.md | 12 +++++ README.md | 1 + composer.json | 4 +- .../Message/CustomerCreditTransfer.php | 2 +- .../Money/{Mixed.php => MixedMoney.php} | 2 +- .../PaymentInformation/PaymentInformation.php | 4 +- tests/Z38/SwissPayment/Tests/BICTest.php | 4 +- .../SwissPayment/Tests/GeneralAccountTest.php | 6 +-- tests/Z38/SwissPayment/Tests/IBANTest.php | 10 ++-- tests/Z38/SwissPayment/Tests/IIDTest.php | 4 +- .../SwissPayment/Tests/ISRParticipantTest.php | 6 +-- .../Message/CustomerCreditTransferTest.php | 8 ++-- .../SwissPayment/Tests/Money/MixedTest.php | 8 ++-- .../SwissPayment/Tests/Money/MoneyTest.php | 46 +++++++++---------- .../CategoryPurposeCodeTest.php | 8 ++-- .../PaymentInformationTest.php | 10 ++-- .../SEPAPaymentInformationTest.php | 8 ++-- .../SwissPayment/Tests/PostalAccountTest.php | 13 +++--- tests/Z38/SwissPayment/Tests/TextTest.php | 30 +++++------- .../BankCreditTransferTest.php | 4 +- .../ForeignCreditTransferTest.php | 2 +- .../IS1CreditTransferTest.php | 2 +- .../IS2CreditTransferTest.php | 2 +- .../ISRCreditTransferTest.php | 8 ++-- .../PurposeCodeTest.php | 8 ++-- 26 files changed, 110 insertions(+), 104 deletions(-) rename src/Z38/SwissPayment/Money/{Mixed.php => MixedMoney.php} (98%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f71a28f..9f50297 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - php: ['7.0', '7.1', '7.2', '7.3', '7.4'] + php: ['7.2', '7.3', '7.4', '8.0'] stability: ['prefer-lowest', 'prefer-stable'] fail-fast: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c0745..b5e60d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # SwissPayment Changelog +## 2.0.0 (2021-10-19) + + * Added support for QR Bills (BankCreditTransferWithCreditorReference, BankCreditTransferWithQRR) + * Renamed Mixed to MixedMoney (reserved word as of PHP 7). + * Added Support for PHP 8.0 + * Dropped support for PHP 7.1 and 7.2 + +## 1.0.0 (2021-10-18) + + * Forked from z38/swiss-payment due to lack of maintenance on the old Project + * Dropped support for PHP 5.6. + ## 0.7.0 (2019-01-05) * Support creation of IIDs from Lichtenstein IBANs. diff --git a/README.md b/README.md index 0ed5e1d..2967137 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # SwissPayment [![Build Status](https://github.com/ch2877/swiss-payment/actions/workflows/tests.yml/badge.svg)](https://github.com/ch2877/swiss-payment/actions) +[![Tested on PHP PHP 7.2, 7.3, 7.4, 8.0](https://img.shields.io/badge/tested%20on-7.2%20|%207.3%20|%207.4%20|%208.0%20-brightgreen.svg?maxAge=2419200)](https://github.com/ch2877/swiss-payment/actions?query=workflow%3ATest) **SwissPayment** is a PHP library to generate Swiss pain.001 XML messages (complies with ISO-20022). diff --git a/composer.json b/composer.json index 1a324c0..9cb1126 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ } ], "require": { - "php": "^7" + "php": ">=7.2|^8.0" }, "require-dev": { - "phpunit/phpunit": "^6 | ^8" + "phpunit/phpunit": "^8.0|^9.0" }, "autoload": { "psr-0": { diff --git a/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php b/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php index a478112..9292e41 100644 --- a/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php +++ b/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php @@ -107,7 +107,7 @@ protected function getSchemaLocation() protected function buildDom(\DOMDocument $doc) { $transactionCount = 0; - $transactionSum = new Money\Mixed(0); + $transactionSum = new Money\MixedMoney(0); foreach ($this->payments as $payment) { $transactionCount += $payment->getTransactionCount(); $transactionSum = $transactionSum->plus($payment->getTransactionSum()); diff --git a/src/Z38/SwissPayment/Money/Mixed.php b/src/Z38/SwissPayment/Money/MixedMoney.php similarity index 98% rename from src/Z38/SwissPayment/Money/Mixed.php rename to src/Z38/SwissPayment/Money/MixedMoney.php index 4a2dc62..a63548a 100644 --- a/src/Z38/SwissPayment/Money/Mixed.php +++ b/src/Z38/SwissPayment/Money/MixedMoney.php @@ -5,7 +5,7 @@ /** * Sum of money in mixed currencies */ -class Mixed extends Money +class MixedMoney extends Money { /** * @var int diff --git a/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php b/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php index 2bea818..5c334c4 100644 --- a/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php +++ b/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php @@ -117,11 +117,11 @@ public function getTransactionCount() /** * Gets the sum of transactions * - * @return Money\Mixed Sum of transactions + * @return Money\MixedMoney Sum of transactions */ public function getTransactionSum() { - $sum = new Money\Mixed(0); + $sum = new Money\MixedMoney(0); foreach ($this->transactions as $transaction) { $sum = $sum->plus($transaction->getAmount()); diff --git a/tests/Z38/SwissPayment/Tests/BICTest.php b/tests/Z38/SwissPayment/Tests/BICTest.php index ef82da9..ce4a84f 100644 --- a/tests/Z38/SwissPayment/Tests/BICTest.php +++ b/tests/Z38/SwissPayment/Tests/BICTest.php @@ -40,7 +40,7 @@ public function testInvalidChars() public function testFormat($bic) { $instance = new BIC($bic); - $this->assertEquals($bic, $instance->format()); + self::assertEquals($bic, $instance->format()); } public function validSamples() @@ -60,6 +60,6 @@ protected function check($iban, $valid) } catch (\InvalidArgumentException $e) { $exception = true; } - $this->assertTrue($exception != $valid); + self::assertTrue($exception != $valid); } } diff --git a/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php b/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php index f5aac07..4a5954f 100644 --- a/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php +++ b/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php @@ -2,7 +2,6 @@ namespace Z38\SwissPayment\Tests; -use InvalidArgumentException; use Z38\SwissPayment\GeneralAccount; class GeneralAccountTest extends TestCase @@ -13,14 +12,15 @@ class GeneralAccountTest extends TestCase public function testValid() { $instance = new GeneralAccount('A-123-4567890-78'); + self::assertInstanceOf(GeneralAccount::class, $instance); } /** * @covers \Z38\SwissPayment\GeneralAccount::__construct - * @expectedException InvalidArgumentException */ public function testInvalid() { + $this->expectException(\InvalidArgumentException::class); $instance = new GeneralAccount('0123456789012345678901234567890123456789'); } @@ -30,6 +30,6 @@ public function testInvalid() public function testFormat() { $instance = new GeneralAccount(' 123-4567890-78 AA '); - $this->assertSame(' 123-4567890-78 AA ', $instance->format()); + self::assertSame(' 123-4567890-78 AA ', $instance->format()); } } diff --git a/tests/Z38/SwissPayment/Tests/IBANTest.php b/tests/Z38/SwissPayment/Tests/IBANTest.php index 1f92a53..3d50931 100644 --- a/tests/Z38/SwissPayment/Tests/IBANTest.php +++ b/tests/Z38/SwissPayment/Tests/IBANTest.php @@ -40,7 +40,7 @@ public function testWrongChecksum() public function testGetCountry($iban, $expectedCountry) { $instance = new IBAN($iban); - $this->assertEquals($expectedCountry, $instance->getCountry()); + self::assertEquals($expectedCountry, $instance->getCountry()); } /** @@ -49,7 +49,7 @@ public function testGetCountry($iban, $expectedCountry) public function testFormat() { $iban = new IBAN('ch9300762011623852 957'); - $this->assertEquals('CH93 0076 2011 6238 5295 7', $iban->format()); + self::assertEquals('CH93 0076 2011 6238 5295 7', $iban->format()); } /** @@ -58,7 +58,7 @@ public function testFormat() public function testNormalize() { $iban = new IBAN('fr14 2004 10100505 0001 3M02 606'); - $this->assertEquals('FR1420041010050500013M02606', $iban->normalize()); + self::assertEquals('FR1420041010050500013M02606', $iban->normalize()); } /** @@ -69,7 +69,7 @@ public function testNormalize() public function testToString($iban) { $instance = new IBAN($iban); - $this->assertEquals($instance->format(), (string) $instance); + self::assertEquals($instance->format(), (string) $instance); } public function samplesValid() @@ -89,6 +89,6 @@ protected function check($iban, $valid) } catch (\InvalidArgumentException $e) { $exception = true; } - $this->assertTrue($exception != $valid); + self::assertTrue($exception != $valid); } } diff --git a/tests/Z38/SwissPayment/Tests/IIDTest.php b/tests/Z38/SwissPayment/Tests/IIDTest.php index 7afe0f1..ac16bb6 100644 --- a/tests/Z38/SwissPayment/Tests/IIDTest.php +++ b/tests/Z38/SwissPayment/Tests/IIDTest.php @@ -32,10 +32,10 @@ public function validSamples() /** * @dataProvider invalidSamples * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidLength($iid) { + $this->expectException(\InvalidArgumentException::class); new IID($iid); } @@ -79,10 +79,10 @@ public function fromIBANSamples() /** * @cover ::fromIban - * @expectedException \InvalidArgumentException */ public function testFromIBANForeign() { + $this->expectException(\InvalidArgumentException::class); IID::fromIBAN(new IBAN('GB29 NWBK 6016 1331 9268 19')); } diff --git a/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php b/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php index dd9f654..bc13b01 100644 --- a/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php +++ b/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php @@ -15,16 +15,16 @@ class ISRParticipantTest extends TestCase */ public function testValid($number) { - $this->assertInstanceOf('Z38\SwissPayment\ISRParticipant', new ISRParticipant($number)); + self::assertInstanceOf('Z38\SwissPayment\ISRParticipant', new ISRParticipant($number)); } /** * @dataProvider invalidSamples * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalid($number) { + $this->expectException(\InvalidArgumentException::class); new ISRParticipant($number); } @@ -34,7 +34,7 @@ public function testInvalid($number) public function testFormat() { $instance = new ISRParticipant('010001628'); - $this->assertEquals('01-162-8', $instance->format()); + self::assertEquals('01-162-8', $instance->format()); } public function validSamples() diff --git a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php index 24cdf97..fb3a301 100644 --- a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php @@ -263,10 +263,10 @@ public function testGroupHeader() $xpath->registerNamespace('pain001', self::SCHEMA); $nbOfTxs = $xpath->evaluate('string(//pain001:GrpHdr/pain001:NbOfTxs)'); - $this->assertEquals('14', $nbOfTxs); + self::assertEquals('14', $nbOfTxs); $ctrlSum = $xpath->evaluate('string(//pain001:GrpHdr/pain001:CtrlSum)'); - $this->assertEquals('6810.001', $ctrlSum); + self::assertEquals('6810.001', $ctrlSum); } public function testSchemaValidation() @@ -282,7 +282,7 @@ public function testSchemaValidation() foreach (libxml_get_errors() as $error) { $this->fail($error->message); } - $this->assertTrue($valid); + self::assertTrue($valid); libxml_clear_errors(); libxml_use_internal_errors(false); } @@ -291,6 +291,6 @@ public function testGetPaymentCount() { $message = $this->buildMessage(); - $this->assertSame(6, $message->getPaymentCount()); + self::assertSame(6, $message->getPaymentCount()); } } diff --git a/tests/Z38/SwissPayment/Tests/Money/MixedTest.php b/tests/Z38/SwissPayment/Tests/Money/MixedTest.php index 19b9e26..bb74404 100644 --- a/tests/Z38/SwissPayment/Tests/Money/MixedTest.php +++ b/tests/Z38/SwissPayment/Tests/Money/MixedTest.php @@ -8,11 +8,11 @@ class MixedTest extends TestCase { /** - * @covers \Z38\SwissPayment\Money\Mixed::plus + * @covers \Z38\SwissPayment\Money\MixedMoney::plus */ public function testPlus() { - $sum = new Money\Mixed(0); + $sum = new Money\MixedMoney(0); $sum = $sum->plus(new Money\CHF(2456)); $sum = $sum->plus(new Money\CHF(1000)); $sum = $sum->plus(new Money\JPY(1200)); @@ -21,11 +21,11 @@ public function testPlus() } /** - * @covers \Z38\SwissPayment\Money\Mixed::minus + * @covers \Z38\SwissPayment\Money\MixedMoney::minus */ public function testMinus() { - $sum = new Money\Mixed(100); + $sum = new Money\MixedMoney(100); $sum = $sum->minus(new Money\CHF(5000)); $sum = $sum->minus(new Money\CHF(99)); $sum = $sum->minus(new Money\JPY(300)); diff --git a/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php b/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php index c89601e..35570bc 100644 --- a/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php +++ b/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php @@ -13,16 +13,16 @@ class MoneyTest extends TestCase public function testFormatWithDecimals() { $zero = new Money\CHF(0); - $this->assertEquals('0.00', $zero->format()); + self::assertEquals('0.00', $zero->format()); $money = new Money\CHF(1234567); - $this->assertEquals('12345.67', $money->format()); + self::assertEquals('12345.67', $money->format()); $money = new Money\CHF(-1234567); - $this->assertEquals('-12345.67', $money->format()); + self::assertEquals('-12345.67', $money->format()); $money = new Money\CHF(-2); - $this->assertEquals('-0.02', $money->format()); + self::assertEquals('-0.02', $money->format()); } /** @@ -31,13 +31,13 @@ public function testFormatWithDecimals() public function testFormatWithoutDecimals() { $zero = new Money\JPY(0); - $this->assertEquals('0', $zero->format()); + self::assertEquals('0', $zero->format()); $money = new Money\JPY(123); - $this->assertEquals('123', $money->format()); + self::assertEquals('123', $money->format()); $money = new Money\JPY(-1123); - $this->assertEquals('-1123', $money->format()); + self::assertEquals('-1123', $money->format()); } /** @@ -46,13 +46,13 @@ public function testFormatWithoutDecimals() public function testGetAmount() { $instance = new Money\CHF(345); - $this->assertEquals(345, $instance->getAmount()); + self::assertEquals(345, $instance->getAmount()); $instance = new Money\CHF(-345); - $this->assertEquals(-345, $instance->getAmount()); + self::assertEquals(-345, $instance->getAmount()); $instance = new Money\CHF(0); - $this->assertEquals(0, $instance->getAmount()); + self::assertEquals(0, $instance->getAmount()); } /** @@ -62,14 +62,14 @@ public function testEquals() { $instance = new Money\CHF(-451); - $this->assertTrue($instance->equals($instance)); - $this->assertTrue($instance->equals(new Money\CHF(-451))); + self::assertTrue($instance->equals($instance)); + self::assertTrue($instance->equals(new Money\CHF(-451))); - $this->assertFalse($instance->equals(false)); - $this->assertFalse($instance->equals(null)); - $this->assertFalse($instance->equals(new \stdClass())); - $this->assertFalse($instance->equals(new Money\EUR(-451))); - $this->assertFalse($instance->equals(new Money\CHF(-41))); + self::assertFalse($instance->equals(false)); + self::assertFalse($instance->equals(null)); + self::assertFalse($instance->equals(new \stdClass())); + self::assertFalse($instance->equals(new Money\EUR(-451))); + self::assertFalse($instance->equals(new Money\CHF(-41))); } /** @@ -80,38 +80,38 @@ public function testEquals() */ public function testBinaryOperands($a, $b, $expectedSum, $expectedDiff, $expectedComparison) { - $this->assertTrue($expectedSum->equals($a->plus($b))); - $this->assertTrue($expectedDiff->equals($a->minus($b))); - $this->assertEquals($expectedComparison, $a->compareTo($b)); + self::assertTrue($expectedSum->equals($a->plus($b))); + self::assertTrue($expectedDiff->equals($a->minus($b))); + self::assertEquals($expectedComparison, $a->compareTo($b)); } /** - * @expectedException \InvalidArgumentException * @dataProvider invalidSamplePairs * @covers \Z38\SwissPayment\Money\Money::plus */ public function testInvalidPlus($a, $b) { + $this->expectException(\InvalidArgumentException::class); $a->plus($b); } /** - * @expectedException \InvalidArgumentException * @dataProvider invalidSamplePairs * @covers \Z38\SwissPayment\Money\Money::minus */ public function testInvalidMinus($a, $b) { + $this->expectException(\InvalidArgumentException::class); $a->minus($b); } /** - * @expectedException \InvalidArgumentException * @dataProvider invalidSamplePairs * @covers \Z38\SwissPayment\Money\Money::minus */ public function testInvalidCompareTo($a, $b) { + $this->expectException(\InvalidArgumentException::class); $a->compareTo($b); } diff --git a/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php b/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php index dc7be18..818a91a 100644 --- a/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php +++ b/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php @@ -17,7 +17,7 @@ class CategoryPurposeCodeTest extends TestCase */ public function testValid($code) { - $this->assertInstanceOf('Z38\SwissPayment\PaymentInformation\CategoryPurposeCode', new CategoryPurposeCode($code)); + self::assertInstanceOf('Z38\SwissPayment\PaymentInformation\CategoryPurposeCode', new CategoryPurposeCode($code)); } public function validSamples() @@ -31,10 +31,10 @@ public function validSamples() /** * @dataProvider invalidSamples * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalid($code) { + $this->expectException(\InvalidArgumentException::class); new CategoryPurposeCode($code); } @@ -59,7 +59,7 @@ public function testAsDom() $xml = $iid->asDom($doc); - $this->assertSame('Cd', $xml->nodeName); - $this->assertSame('SALA', $xml->textContent); + self::assertSame('Cd', $xml->nodeName); + self::assertSame('SALA', $xml->textContent); } } diff --git a/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php b/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php index d66a334..0cab342 100644 --- a/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php +++ b/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php @@ -22,10 +22,10 @@ class PaymentInformationTest extends TestCase { /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidDebtorAgent() { + $this->expectException(\InvalidArgumentException::class); $debtorAgent = $this->createMock(FinancialInstitutionInterface::class); $payment = new PaymentInformation( @@ -84,9 +84,9 @@ public function testInfersPaymentInformation() $xml = $payment->asDom($doc); $xpath = new DOMXPath($doc); - $this->assertNull($payment->getServiceLevel()); - $this->assertNull($payment->getLocalInstrument()); - $this->assertSame('CH02', $xpath->evaluate('string(./PmtTpInf/LclInstrm/Prtry)', $xml)); - $this->assertSame(0.0, $xpath->evaluate('count(./CdtTrfTxInf/PmtTpInf/LclInstrm/Prtry)', $xml)); + self::assertNull($payment->getServiceLevel()); + self::assertNull($payment->getLocalInstrument()); + self::assertSame('CH02', $xpath->evaluate('string(./PmtTpInf/LclInstrm/Prtry)', $xml)); + self::assertSame(0.0, $xpath->evaluate('count(./CdtTrfTxInf/PmtTpInf/LclInstrm/Prtry)', $xml)); } } diff --git a/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php b/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php index 58ba63f..6861e4e 100644 --- a/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php +++ b/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php @@ -58,17 +58,17 @@ public function testAsDomWithSEPATransaction() $doc->appendChild($dom); $xpath = new \DOMXPath($doc); - $this->assertEquals('SEPA', $xpath->evaluate('string(/PmtInf/PmtTpInf/SvcLvl/Cd)')); - $this->assertEquals(0, $xpath->evaluate('count(//CdtTrfTxInf/PmtTpInf)')); + self::assertEquals('SEPA', $xpath->evaluate('string(/PmtInf/PmtTpInf/SvcLvl/Cd)')); + self::assertEquals(0, $xpath->evaluate('count(//CdtTrfTxInf/PmtTpInf)')); } /** * @covers ::asDom - * @expectedException \LogicException - * @expectedExceptionMessage You can not set the service level on B- and C-level. */ public function testAsDomWithNonSEPATransaction() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('You can not set the service level on B- and C-level.'); $payment = new SEPAPaymentInformation( 'id000', 'name', diff --git a/tests/Z38/SwissPayment/Tests/PostalAccountTest.php b/tests/Z38/SwissPayment/Tests/PostalAccountTest.php index d4f0234..aa28445 100644 --- a/tests/Z38/SwissPayment/Tests/PostalAccountTest.php +++ b/tests/Z38/SwissPayment/Tests/PostalAccountTest.php @@ -2,7 +2,6 @@ namespace Z38\SwissPayment\Tests; -use InvalidArgumentException; use Z38\SwissPayment\PostalAccount; /** @@ -16,7 +15,7 @@ class PostalAccountTest extends TestCase */ public function testValid($postalAccount) { - $this->assertInstanceOf('Z38\SwissPayment\PostalAccount', new PostalAccount($postalAccount)); + self::assertInstanceOf('Z38\SwissPayment\PostalAccount', new PostalAccount($postalAccount)); } public function validSamples() @@ -35,11 +34,11 @@ public function validSamples() /** * @dataProvider invalidFormatSamples * @covers ::__construct - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Postal account number is not properly formatted. */ public function testInvalidFormat($postalAccount) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Postal account number is not properly formatted.'); new PostalAccount($postalAccount); } @@ -57,11 +56,11 @@ public function invalidFormatSamples() /** * @dataProvider invalidCheckDigitSamples * @covers ::__construct - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Postal account number has an invalid check digit. */ public function testInvalidCheckDigit($postalAccount) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Postal account number has an invalid check digit.'); new PostalAccount($postalAccount); } @@ -81,6 +80,6 @@ public function invalidCheckDigitSamples() public function testFormat($postalAccount) { $instance = new PostalAccount($postalAccount); - $this->assertEquals($postalAccount, $instance->format()); + self::assertEquals($postalAccount, $instance->format()); } } diff --git a/tests/Z38/SwissPayment/Tests/TextTest.php b/tests/Z38/SwissPayment/Tests/TextTest.php index f43230e..89aa1c8 100644 --- a/tests/Z38/SwissPayment/Tests/TextTest.php +++ b/tests/Z38/SwissPayment/Tests/TextTest.php @@ -11,57 +11,49 @@ class TextTest extends TestCase { /** - * @expectedException \InvalidArgumentException */ public function testAssertTooLong() { + $this->expectException(\InvalidArgumentException::class); Text::assert('abcd', 3); } public function testAssertMaximumLength() { - $this->assertSame('abcd', Text::assert('abcd', 4)); + self::assertSame('abcd', Text::assert('abcd', 4)); } public function testAssertUnicode() { - $this->assertSame('÷ß', Text::assert('÷ß', 2)); + self::assertSame('÷ß', Text::assert('÷ß', 2)); } - /** - * @expectedException \InvalidArgumentException - */ public function testAssertInvalid() { + $this->expectException(\InvalidArgumentException::class); Text::assert('°', 10); } - /** - * @expectedException \InvalidArgumentException - */ public function testAssertIdentiferBeginsWithSlash() { + $this->expectException(\InvalidArgumentException::class); Text::assertIdentifier('/abc'); } - /** - * @expectedException \InvalidArgumentException - */ public function testAssertIdentiferContainsDoubleSlash() { + $this->expectException(\InvalidArgumentException::class); Text::assertIdentifier('ab//c'); } public function testAssertIdentiferContainsSlash() { - $this->assertSame('ab/c', Text::assertIdentifier('ab/c')); + self::assertSame('ab/c', Text::assertIdentifier('ab/c')); } - /** - * @expectedException \InvalidArgumentException - */ public function testAssertCountryCodeUppercase() { + $this->expectException(\InvalidArgumentException::class); Text::assertCountryCode('ch'); } @@ -70,7 +62,7 @@ public function testAssertCountryCodeUppercase() */ public function testSanitize($input, $expected) { - $this->assertSame($expected, Text::sanitize($input, 3)); + self::assertSame($expected, Text::sanitize($input, 3)); } public function sanitizeSamples() @@ -86,7 +78,7 @@ public function sanitizeSamples() public function testSanitizeOptional() { - $this->assertSame(null, Text::sanitizeOptional(" \t ° ° \t", 100)); + self::assertSame(null, Text::sanitizeOptional(" \t ° ° \t", 100)); } public function testXml() @@ -95,6 +87,6 @@ public function testXml() $element = Text::xml($doc, 'abc', '<>&'); - $this->assertSame('<>&', $doc->saveXML($element)); + self::assertSame('<>&', $doc->saveXML($element)); } } diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php index b329a1a..3f28325 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php @@ -17,12 +17,12 @@ class BankCreditTransferTest extends TestCase { /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidCreditorAgent() { $creditorAgent = $this->createMock(FinancialInstitutionInterface::class); + $this->expectException(\InvalidArgumentException::class); $transfer = new BankCreditTransfer( 'id000', 'name', @@ -36,10 +36,10 @@ public function testInvalidCreditorAgent() /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidAmount() { + $this->expectException(\InvalidArgumentException::class); $transfer = new BankCreditTransfer( 'id000', 'name', diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php index 54c9dca..93fc4ec 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php @@ -16,10 +16,10 @@ class ForeignCreditTransferTest extends TestCase { /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidCreditorAgent() { + $this->expectException(\InvalidArgumentException::class); $creditorAgent = $this->createMock(FinancialInstitutionInterface::class); $transfer = new ForeignCreditTransfer( diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php index 410edf3..754ce7b 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php @@ -15,10 +15,10 @@ class IS1CreditTransferTest extends TestCase { /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidAmount() { + $this->expectException(\InvalidArgumentException::class); $transfer = new IS1CreditTransfer( 'id000', 'name', diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php index d306352..1b0692a 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php @@ -16,10 +16,10 @@ class IS2CreditTransferTest extends TestCase { /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidAmount() { + $this->expectException(\InvalidArgumentException::class); $transfer = new IS2CreditTransfer( 'id000', 'name', diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php index c311f9b..a638b06 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php @@ -15,10 +15,10 @@ class ISRCreditTransferTest extends TestCase { /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidAmount() { + $this->expectException(\InvalidArgumentException::class); $transfer = new ISRCreditTransfer( 'id000', 'name', @@ -30,10 +30,10 @@ public function testInvalidAmount() /** * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalidCreditorReference() { + $this->expectException(\InvalidArgumentException::class); $transfer = new ISRCreditTransfer( 'id000', 'name', @@ -45,10 +45,10 @@ public function testInvalidCreditorReference() /** * @covers ::setRemittanceInformation - * @expectedException \LogicException */ public function testSetRemittanceInformation() { + $this->expectException(\LogicException::class); $transfer = new ISRCreditTransfer( 'id000', 'name', @@ -76,5 +76,7 @@ public function testCreditorDetails() $creditorName = 'name'; $creditorAddress = new StructuredPostalAddress('foo', '99', '9999', 'bar'); $transfer->setCreditorDetails($creditorName, $creditorAddress); + + self::assertInstanceOf(ISRCreditTransfer::class, $transfer); } } diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php index 932006b..604709d 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php @@ -17,7 +17,7 @@ class PurposeCodeTest extends TestCase */ public function testValid($code) { - $this->assertInstanceOf('Z38\SwissPayment\TransactionInformation\PurposeCode', new PurposeCode($code)); + self::assertInstanceOf('Z38\SwissPayment\TransactionInformation\PurposeCode', new PurposeCode($code)); } public function validSamples() @@ -33,10 +33,10 @@ public function validSamples() /** * @dataProvider invalidSamples * @covers ::__construct - * @expectedException \InvalidArgumentException */ public function testInvalid($code) { + $this->expectException(\InvalidArgumentException::class); new PurposeCode($code); } @@ -60,7 +60,7 @@ public function testAsDom() $xml = $iid->asDom($doc); - $this->assertSame('Cd', $xml->nodeName); - $this->assertSame('PHON', $xml->textContent); + self::assertSame('Cd', $xml->nodeName); + self::assertSame('PHON', $xml->textContent); } }