Skip to content

Commit

Permalink
Raising test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mschindler committed Aug 24, 2016
1 parent 02e54fd commit 5c213ad
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 58 deletions.
3 changes: 2 additions & 1 deletion Samples/statement_of_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 0 additions & 26 deletions lib/Fhp/Model/SEPAAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
class SEPAAccount
{
/** @var bool */
protected $isSepaCapable;
/** @var string */
protected $iban;
/** @var string */
Expand All @@ -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
*
Expand Down
12 changes: 6 additions & 6 deletions lib/Fhp/Model/StatementOfAccount/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class Statement
/**
* @var float
*/
protected $startBalance;
protected $startBalance = 0.0;

/**
* @var string
*/
protected $creditDebit;

/**
* @var \DateTime
* @var \DateTime|null
*/
protected $date;

Expand All @@ -48,7 +48,7 @@ public function getTransactions()
*
* @return $this
*/
public function setTransactions(array $transactions)
public function setTransactions(array $transactions = null)
{
$this->transactions = $transactions;

Expand Down Expand Up @@ -79,7 +79,7 @@ public function getStartBalance()
*/
public function setStartBalance($startBalance)
{
$this->startBalance = $startBalance;
$this->startBalance = (float) $startBalance;

return $this;
}
Expand All @@ -97,7 +97,7 @@ public function getCreditDebit()
/**
* Set creditDebit
*
* @param mixed $creditDebit
* @param string|null $creditDebit
*
* @return $this
*/
Expand Down Expand Up @@ -125,7 +125,7 @@ public function getDate()
*
* @return $this
*/
public function setDate($date)
public function setDate(\DateTime $date)
{
$this->date = $date;

Expand Down
4 changes: 2 additions & 2 deletions lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Fhp/Model/StatementOfAccount/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
class Transaction
{
const CD_CREDIT = 'credit';
const CD_DEBIT = 'debit';

/**
* @var \DateTime|null
*/
Expand Down Expand Up @@ -62,6 +65,7 @@ class Transaction
* Get booking date.
*
* @deprecated Use getBookingDate() instead
* @codeCoverageIgnore
* @return \DateTime|null
*/
public function getDate()
Expand Down
1 change: 1 addition & 0 deletions lib/Fhp/Parser/MT940.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function parse($target)

/**
* @return array
* @throws MT940Exception
*/
protected function parseToArray()
{
Expand Down
50 changes: 27 additions & 23 deletions lib/Tests/Fhp/Model/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
25 changes: 25 additions & 0 deletions lib/Tests/Fhp/Model/SEPAAccountTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Tests\Fhp\Model;

use Fhp\Model\SEPAAccount;

class SEPAAccountTest extends \PHPUnit_Framework_TestCase
{
public function test_getter_and_setter()
{
$obj = new SEPAAccount();

$this->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());
}
}
33 changes: 33 additions & 0 deletions lib/Tests/Fhp/Model/StatementOfAccount/StatementOfAccountTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Tests\Fhp\Model\StatementOfAccount;

use Fhp\Model\StatementOfAccount\Statement;
use Fhp\Model\StatementOfAccount\StatementOfAccount;

class StatementOfAccountTest extends \PHPUnit_Framework_TestCase
{
public function test_getter_and_setter()
{
$obj = new StatementOfAccount();
$this->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());
}
}
58 changes: 58 additions & 0 deletions lib/Tests/Fhp/Model/StatementOfAccount/StatementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Tests\Fhp\Model\StatementOfAccount;

use Fhp\Model\StatementOfAccount\Statement;
use Fhp\Model\StatementOfAccount\Transaction;

class StatementTest extends \PHPUnit_Framework_TestCase
{
public function test_getter_and_setter()
{
$obj = new Statement();

$this->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());
}
}
37 changes: 37 additions & 0 deletions lib/Tests/Fhp/Model/StatementOfAccount/TransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Tests\Fhp\Model\StatementOfAccount;

use Fhp\Model\StatementOfAccount\Transaction;

class TransactionTest extends \PHPUnit_Framework_TestCase
{
public function test_getter_and_setter()
{
$obj = new Transaction();

$this->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());
}
}

0 comments on commit 5c213ad

Please sign in to comment.