From 4e5d393e2c0250e9190b520ca66b1bec99b7c840 Mon Sep 17 00:00:00 2001 From: Carlo Capocasa Date: Tue, 15 Apr 2014 11:00:02 +0200 Subject: [PATCH] Revert "changed handling of transfer amounts as this lead ton an erro #28" This reverts commit 3ce27b02687589ac1cd0f31463e4a969bb779c3d. --- .../BaseTransferInformation.php | 9 +- phpunit.xml.dist | 8 +- tests/Unit/SumOutputTest.php | 144 ------------------ 3 files changed, 3 insertions(+), 158 deletions(-) delete mode 100644 tests/Unit/SumOutputTest.php diff --git a/lib/Digitick/Sepa/TransferInformation/BaseTransferInformation.php b/lib/Digitick/Sepa/TransferInformation/BaseTransferInformation.php index bec5197..edce412 100644 --- a/lib/Digitick/Sepa/TransferInformation/BaseTransferInformation.php +++ b/lib/Digitick/Sepa/TransferInformation/BaseTransferInformation.php @@ -23,7 +23,6 @@ namespace Digitick\Sepa\TransferInformation; use Digitick\Sepa\DomBuilder\DomBuilderInterface; -use Digitick\Sepa\Exception\InvalidArgumentException; use Digitick\Sepa\Util\StringHelper; class BaseTransferInformation implements TransferInformationInterface @@ -84,11 +83,7 @@ class BaseTransferInformation implements TransferInformationInterface public function __construct($amount, $iban, $name) { $amount += 0; if (is_float($amount)) { - if(!function_exists('bcscale')) { - throw new InvalidArgumentException('Using floats for amount is only possible with bcmath enabled'); - } - bcscale(2); - $amount = (integer)bcmul($amount, 100); + $amount = (integer) ($amount * 100); } $this->transferAmount = $amount; $this->iban = $iban; @@ -194,4 +189,4 @@ public function getRemittanceInformation() { return $this->remittanceInformation; } -} +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7f12fe1..4bc87ee 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,6 @@ - + diff --git a/tests/Unit/SumOutputTest.php b/tests/Unit/SumOutputTest.php deleted file mode 100644 index aa9f27a..0000000 --- a/tests/Unit/SumOutputTest.php +++ /dev/null @@ -1,144 +0,0 @@ -addPaymentInfo( - 'firstPayment', - array( - 'id' => 'firstPayment', - 'creditorName' => 'My Company', - 'creditorAccountIBAN' => 'FI1350001540000056', - 'creditorAgentBIC' => 'PSSTFRPPMON', - 'seqType' => PaymentInformation::S_ONEOFF, - 'creditorId' => 'DE21WVM1234567890' - ) - ); - // Add a Single Transaction to the named payment - $directDebit->addTransfer( - 'firstPayment', - array( - 'amount' => $amount, - 'debtorIban' => 'FI1350001540000056', - 'debtorBic' => 'OKOYFIHH', - 'debtorName' => 'Their Company', - 'debtorMandate' => 'AB12345', - 'debtorMandateSignDate' => '13.10.2012', - 'remittanceInformation' => 'Purpose of this direct debit' - ) - ); - // Retrieve the resulting XML - $xml = $directDebit->asXML(); - $doc = new \DOMDocument(); - $doc->loadXML($xml); - $this->directDebitXpath = new \DOMXPath($doc); - $this->directDebitXpath->registerNamespace('sepa', 'urn:iso:std:iso:20022:tech:xsd:pain.008.002.02'); - } - - /** - * @test - */ - public function validSumIsCalculatedCorrectly() - { - $this->createDirectDebitXpathObject('19.99'); - $controlSum = $this->directDebitXpath->query('//sepa:GrpHdr/sepa:CtrlSum'); - $this->assertEquals('19.99', $controlSum->item(0)->textContent, 'GroupHeader ControlSum should be 19.99'); - - $controlSum = $this->directDebitXpath->query('//sepa:PmtInf/sepa:CtrlSum'); - $this->assertEquals( - '19.99', - $controlSum->item(0)->textContent, - 'PaymentInformation ControlSum should be 19.99' - ); - $controlSum = $this->directDebitXpath->query('//sepa:DrctDbtTxInf/sepa:InstdAmt'); - $this->assertEquals( - '19.99', - $controlSum->item(0)->textContent, - 'DirectDebitTransferInformation InstructedAmount should be 19.99' - ); - } - - /** - * @test - */ - public function floatSumIsCalculatedCorrectly() - { - $this->createDirectDebitXpathObject('19.999'); - $controlSum = $this->directDebitXpath->query('//sepa:GrpHdr/sepa:CtrlSum'); - $this->assertEquals('19.99', $controlSum->item(0)->textContent, 'GroupHeader ControlSum should be 19.99'); - - $controlSum = $this->directDebitXpath->query('//sepa:PmtInf/sepa:CtrlSum'); - $this->assertEquals( - '19.99', - $controlSum->item(0)->textContent, - 'PaymentInformation ControlSum should be 19.99' - ); - $controlSum = $this->directDebitXpath->query('//sepa:DrctDbtTxInf/sepa:InstdAmt'); - $this->assertEquals( - '19.99', - $controlSum->item(0)->textContent, - 'DirectDebitTransferInformation InstructedAmount should be 19.99' - ); - } - - /** - * @test - */ - public function floatsAreAcceptedIfBcMathExtensionIsAvailable() - { - if(!function_exists('bcscale')) { - $this->markTestSkipped('no bcmath extension available'); - } - $transfer = new CustomerDirectDebitTransferInformation( - '19.999', - 'IbanOfDebitor', - 'DebitorName' - ); - - $this->assertEquals(1999, $transfer->getTransferAmount()); - } - - /** - * @test - * @expectedException \Digitick\Sepa\Exception\InvalidArgumentException - */ - public function exceptionIsThrownIfBcMathExtensionIsNotAvailableAndInputIsFloat() - { - if(function_exists('bcscale')) { - $this->markTestSkipped('bcmath extension available, not possible to test exceptions'); - } - $transfer = new CustomerDirectDebitTransferInformation( - '19.999', - 'IbanOfDebitor', - 'DebitorName' - ); - - $this->assertEquals(1999, $transfer->getTransferAmount()); - } -}