From 5c213adef48a386e68162207167d656ee6be13ca Mon Sep 17 00:00:00 2001 From: mschindler Date: Wed, 24 Aug 2016 10:56:30 +0200 Subject: [PATCH] Raising test coverage --- Samples/statement_of_account.php | 3 +- lib/Fhp/Model/SEPAAccount.php | 26 --------- .../Model/StatementOfAccount/Statement.php | 12 ++-- .../StatementOfAccount/StatementOfAccount.php | 4 +- .../Model/StatementOfAccount/Transaction.php | 4 ++ lib/Fhp/Parser/MT940.php | 1 + lib/Tests/Fhp/Model/AccountTest.php | 50 ++++++++-------- lib/Tests/Fhp/Model/SEPAAccountTest.php | 25 ++++++++ .../StatementOfAccountTest.php | 33 +++++++++++ .../StatementOfAccount/StatementTest.php | 58 +++++++++++++++++++ .../StatementOfAccount/TransactionTest.php | 37 ++++++++++++ 11 files changed, 195 insertions(+), 58 deletions(-) create mode 100644 lib/Tests/Fhp/Model/SEPAAccountTest.php create mode 100644 lib/Tests/Fhp/Model/StatementOfAccount/StatementOfAccountTest.php create mode 100644 lib/Tests/Fhp/Model/StatementOfAccount/StatementTest.php create mode 100644 lib/Tests/Fhp/Model/StatementOfAccount/TransactionTest.php diff --git a/Samples/statement_of_account.php b/Samples/statement_of_account.php index 79583f6..8180f87 100644 --- a/Samples/statement_of_account.php +++ b/Samples/statement_of_account.php @@ -9,6 +9,7 @@ use Fhp\FinTs; use Fhp\Model\StatementOfAccount\Statement; +use Fhp\Model\StatementOfAccount\Transaction; define('FHP_BANK_URL', ''); # HBCI / FinTS Url can be found here: https://www.hbci-zka.de/institute/institut_auswahl.htm (use the PIN/TAN URL) define('FHP_BANK_PORT', 443); # HBCI / FinTS Port can be found here: https://www.hbci-zka.de/institute/institut_auswahl.htm @@ -36,7 +37,7 @@ echo 'Transactions:' . PHP_EOL; echo '=======================================' . PHP_EOL; foreach ($statement->getTransactions() as $transaction) { - echo 'Amount : ' . ($transaction->getCreditDebit() == Statement::CD_DEBIT ? '-' : '') . $transaction->getAmount() . PHP_EOL; + echo 'Amount : ' . ($transaction->getCreditDebit() == Transaction::CD_DEBIT ? '-' : '') . $transaction->getAmount() . PHP_EOL; echo 'Booking text: ' . $transaction->getBookingText() . PHP_EOL; echo 'Name : ' . $transaction->getName() . PHP_EOL; echo 'Description : ' . $transaction->getDescription1() . PHP_EOL; diff --git a/lib/Fhp/Model/SEPAAccount.php b/lib/Fhp/Model/SEPAAccount.php index 20ca965..918e167 100644 --- a/lib/Fhp/Model/SEPAAccount.php +++ b/lib/Fhp/Model/SEPAAccount.php @@ -8,8 +8,6 @@ */ class SEPAAccount { - /** @var bool */ - protected $isSepaCapable; /** @var string */ protected $iban; /** @var string */ @@ -21,30 +19,6 @@ class SEPAAccount /** @var string */ protected $blz; - /** - * Get isSepaCapable - * - * @return bool - */ - public function getIsSepaCapable() - { - return $this->isSepaCapable; - } - - /** - * Set isSepaCapable - * - * @param bool $isSepaCapable - * - * @return $this - */ - public function setIsSepaCapable($isSepaCapable) - { - $this->isSepaCapable = (bool) $isSepaCapable; - - return $this; - } - /** * Get iban * diff --git a/lib/Fhp/Model/StatementOfAccount/Statement.php b/lib/Fhp/Model/StatementOfAccount/Statement.php index 489b4b9..b24eb20 100644 --- a/lib/Fhp/Model/StatementOfAccount/Statement.php +++ b/lib/Fhp/Model/StatementOfAccount/Statement.php @@ -19,7 +19,7 @@ class Statement /** * @var float */ - protected $startBalance; + protected $startBalance = 0.0; /** * @var string @@ -27,7 +27,7 @@ class Statement protected $creditDebit; /** - * @var \DateTime + * @var \DateTime|null */ protected $date; @@ -48,7 +48,7 @@ public function getTransactions() * * @return $this */ - public function setTransactions(array $transactions) + public function setTransactions(array $transactions = null) { $this->transactions = $transactions; @@ -79,7 +79,7 @@ public function getStartBalance() */ public function setStartBalance($startBalance) { - $this->startBalance = $startBalance; + $this->startBalance = (float) $startBalance; return $this; } @@ -97,7 +97,7 @@ public function getCreditDebit() /** * Set creditDebit * - * @param mixed $creditDebit + * @param string|null $creditDebit * * @return $this */ @@ -125,7 +125,7 @@ public function getDate() * * @return $this */ - public function setDate($date) + public function setDate(\DateTime $date) { $this->date = $date; diff --git a/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php b/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php index a610125..633a95b 100644 --- a/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php +++ b/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php @@ -30,9 +30,9 @@ public function getStatements() * * @return $this */ - public function setStatements(array $statements) + public function setStatements(array $statements = null) { - $this->statements = $statements; + $this->statements = null == $statements ? array() : $statements; return $this; } diff --git a/lib/Fhp/Model/StatementOfAccount/Transaction.php b/lib/Fhp/Model/StatementOfAccount/Transaction.php index 652ebbe..d86cbb2 100755 --- a/lib/Fhp/Model/StatementOfAccount/Transaction.php +++ b/lib/Fhp/Model/StatementOfAccount/Transaction.php @@ -8,6 +8,9 @@ */ class Transaction { + const CD_CREDIT = 'credit'; + const CD_DEBIT = 'debit'; + /** * @var \DateTime|null */ @@ -62,6 +65,7 @@ class Transaction * Get booking date. * * @deprecated Use getBookingDate() instead + * @codeCoverageIgnore * @return \DateTime|null */ public function getDate() diff --git a/lib/Fhp/Parser/MT940.php b/lib/Fhp/Parser/MT940.php index 06bb54c..1b940ba 100755 --- a/lib/Fhp/Parser/MT940.php +++ b/lib/Fhp/Parser/MT940.php @@ -48,6 +48,7 @@ public function parse($target) /** * @return array + * @throws MT940Exception */ protected function parseToArray() { diff --git a/lib/Tests/Fhp/Model/AccountTest.php b/lib/Tests/Fhp/Model/AccountTest.php index daa18ba..dd48b90 100644 --- a/lib/Tests/Fhp/Model/AccountTest.php +++ b/lib/Tests/Fhp/Model/AccountTest.php @@ -8,42 +8,46 @@ class AccountTest extends \PHPUnit_Framework_TestCase { public function test_getter_and_setter() { - $m = new Account(); - $this->assertNull($m->getId()); - $this->assertNull($m->getAccountDescription()); - $this->assertNull($m->getAccountNumber()); - $this->assertNull($m->getAccountOwnerName()); - $this->assertNull($m->getBankCode()); - $this->assertNull($m->getCurrency()); - $this->assertNull($m->getCustomerId()); - $this->assertNull($m->getIban()); + $obj = new Account(); + $this->assertNull($obj->getId()); + $this->assertNull($obj->getAccountDescription()); + $this->assertNull($obj->getAccountNumber()); + $this->assertNull($obj->getAccountOwnerName()); + $this->assertNull($obj->getBankCode()); + $this->assertNull($obj->getCurrency()); + $this->assertNull($obj->getCustomerId()); + $this->assertNull($obj->getIban()); + + // test id + $obj->setId(10); + $this->assertSame(10, $obj->getId()); // test description - $m->setAccountDescription('Description'); - $this->assertSame('Description', $m->getAccountDescription()); + $obj->setAccountDescription('Description'); + $this->assertSame('Description', $obj->getAccountDescription()); // test account number - $m->setAccountNumber('123123123'); - $this->assertSame('123123123', $m->getAccountNumber()); + $obj->setAccountNumber('123123123'); + $this->assertSame('123123123', $obj->getAccountNumber()); // test account owner name - $m->setAccountOwnerName('The Owner'); - $this->assertSame('The Owner', $m->getAccountOwnerName()); + $obj->setAccountOwnerName('The Owner'); + $this->assertSame('The Owner', $obj->getAccountOwnerName()); // test bank code - $m->setBankCode('123123123'); - $this->assertSame('123123123', $m->getBankCode()); + $obj->setBankCode('123123123'); + $this->assertSame('123123123', $obj->getBankCode()); // test currency - $m->setCurrency('EUR'); - $this->assertSame('EUR', $m->getCurrency()); + $obj->setCurrency('EUR'); + $this->assertSame('EUR', $obj->getCurrency()); // test customer ID - $m->setCustomerId('123123123'); - $this->assertSame('123123123', $m->getCustomerId()); + $obj->setCustomerId('123123123'); + $this->assertSame('123123123', $obj->getCustomerId()); // test iban - $m->setIban('DE123123123123'); - $this->assertSame('DE123123123123', $m->getIban()); + $obj->setIban('DE123123123123'); + $this->assertSame('DE123123123123', $obj->getIban()); } } diff --git a/lib/Tests/Fhp/Model/SEPAAccountTest.php b/lib/Tests/Fhp/Model/SEPAAccountTest.php new file mode 100644 index 0000000..35d4990 --- /dev/null +++ b/lib/Tests/Fhp/Model/SEPAAccountTest.php @@ -0,0 +1,25 @@ +assertNull($obj->getAccountNumber()); + $this->assertNull($obj->getBic()); + $this->assertNull($obj->getBlz()); + $this->assertNull($obj->getIban()); + $this->assertNull($obj->getSubAccount()); + + $this->assertSame('123456789', $obj->setAccountNumber('123456789')->getAccountNumber()); + $this->assertSame('123456789', $obj->setBic('123456789')->getBic()); + $this->assertSame('123456789', $obj->setIban('123456789')->getIban()); + $this->assertSame('123456789', $obj->setBlz('123456789')->getBlz()); + $this->assertSame('123456789', $obj->setSubAccount('123456789')->getSubAccount()); + } +} diff --git a/lib/Tests/Fhp/Model/StatementOfAccount/StatementOfAccountTest.php b/lib/Tests/Fhp/Model/StatementOfAccount/StatementOfAccountTest.php new file mode 100644 index 0000000..5c3d897 --- /dev/null +++ b/lib/Tests/Fhp/Model/StatementOfAccount/StatementOfAccountTest.php @@ -0,0 +1,33 @@ +assertInternalType('array', $obj->getStatements()); + + $s1 = new Statement(); + $s2 = new Statement(); + + $obj->addStatement($s1); + $this->assertInternalType('array', $obj->getStatements()); + $this->assertCount(1, $obj->getStatements()); + $result = $obj->getStatements(); + $this->assertSame($s1, $result[0]); + + $obj->setStatements(null); + $this->assertInternalType('array', $obj->getStatements()); + $this->assertEmpty($obj->getStatements()); + + $obj->setStatements(array($s1, $s2)); + $this->assertInternalType('array', $obj->getStatements()); + $this->assertCount(2, $obj->getStatements()); + $this->assertSame(array($s1, $s2), $obj->getStatements()); + } +} diff --git a/lib/Tests/Fhp/Model/StatementOfAccount/StatementTest.php b/lib/Tests/Fhp/Model/StatementOfAccount/StatementTest.php new file mode 100644 index 0000000..aaebd62 --- /dev/null +++ b/lib/Tests/Fhp/Model/StatementOfAccount/StatementTest.php @@ -0,0 +1,58 @@ +assertInternalType('array', $obj->getTransactions()); + $this->assertEmpty($obj->getTransactions()); + $this->assertSame(0.0, $obj->getStartBalance()); + $this->assertNull($obj->getCreditDebit()); + $this->assertNull($obj->getDate()); + + $trx1 = new Transaction(); + $trx2 = new Transaction(); + + $obj->addTransaction($trx1); + $this->assertCount(1, $obj->getTransactions()); + + $obj->addTransaction($trx2); + $this->assertCount(2, $obj->getTransactions()); + + $obj->setTransactions(null); + $this->assertNull($obj->getTransactions()); + + $obj->setTransactions(array()); + $this->assertInternalType('array', $obj->getTransactions()); + $this->assertCount(0, $obj->getTransactions()); + + $trxArray = array($trx1, $trx2); + $obj->setTransactions($trxArray); + $this->assertInternalType('array', $obj->getTransactions()); + $this->assertCount(2, $obj->getTransactions()); + + $obj->setStartBalance(20.00); + $this->assertInternalType('float', $obj->getStartBalance()); + $this->assertSame(20.00, $obj->getStartBalance()); + + $obj->setStartBalance('string'); + $this->assertSame(0.0, $obj->getStartBalance()); + + $obj->setCreditDebit(Statement::CD_CREDIT); + $this->assertSame(Statement::CD_CREDIT, $obj->getCreditDebit()); + + $obj->setCreditDebit(Statement::CD_DEBIT); + $this->assertSame(Statement::CD_DEBIT, $obj->getCreditDebit()); + + $date = new \DateTime(); + $obj->setDate($date); + $this->assertSame($date, $obj->getDate()); + } +} diff --git a/lib/Tests/Fhp/Model/StatementOfAccount/TransactionTest.php b/lib/Tests/Fhp/Model/StatementOfAccount/TransactionTest.php new file mode 100644 index 0000000..9a44664 --- /dev/null +++ b/lib/Tests/Fhp/Model/StatementOfAccount/TransactionTest.php @@ -0,0 +1,37 @@ +assertNull($obj->getAccountNumber()); + $this->assertNull($obj->getAmount()); + $this->assertNull($obj->getBankCode()); + $this->assertNull($obj->getBookingDate()); + $this->assertNull($obj->getBookingText()); + $this->assertNull($obj->getCreditDebit()); + $this->assertNull($obj->getDescription1()); + $this->assertNull($obj->getDescription2()); + $this->assertNull($obj->getName()); + $this->assertNull($obj->getValutaDate()); + + $date = new \DateTime(); + $this->assertSame('123456789', $obj->setAccountNumber('123456789')->getAccountNumber()); + $this->assertSame(20.00, $obj->setAmount(20.00)->getAmount()); + $this->assertSame('123456789', $obj->setBankCode('123456789')->getBankCode()); + $this->assertSame($date, $obj->setBookingDate($date)->getBookingDate()); + $this->assertSame($date, $obj->setValutaDate($date)->getValutaDate()); + $this->assertSame('text', $obj->setBookingText('text')->getBookingText()); + $this->assertSame(Transaction::CD_DEBIT, $obj->setCreditDebit(Transaction::CD_DEBIT)->getCreditDebit()); + $this->assertSame(Transaction::CD_CREDIT, $obj->setCreditDebit(Transaction::CD_CREDIT)->getCreditDebit()); + $this->assertSame('desc1', $obj->setDescription1('desc1')->getDescription1()); + $this->assertSame('desc2', $obj->setDescription2('desc2')->getDescription2()); + $this->assertSame('name', $obj->setName('name')->getName()); + } +}