mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
ValueObject > BankAccount > represents bank account
This commit is contained in:
@@ -57,6 +57,41 @@ $address = new Address('New York', '00123', '4th Avenue', '10', '200');
|
|||||||
$asString = (string)$address; // "4th Avenue 10/200, 00123, New York"
|
$asString = (string)$address; // "4th Avenue 10/200, 00123, New York"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### BankAccount
|
||||||
|
|
||||||
|
##### Namespace
|
||||||
|
|
||||||
|
`Meritoo\Common\ValueObject\BankAccount`
|
||||||
|
|
||||||
|
##### Info
|
||||||
|
|
||||||
|
Represents bank account. Contains properties:
|
||||||
|
1. `$bankName` - name of bank
|
||||||
|
2. $accountNumber` - number of bank's account
|
||||||
|
|
||||||
|
##### New instance
|
||||||
|
|
||||||
|
New instance can be created using constructor
|
||||||
|
|
||||||
|
```php
|
||||||
|
new BankAccount('Bank of America', '1234567890')
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Methods
|
||||||
|
|
||||||
|
Has getters for each property `getBankName()` and `getAccountNumber()`.
|
||||||
|
|
||||||
|
##### Conversion to string (the `__toString()` method)
|
||||||
|
|
||||||
|
Instance of `BankAccount` may be represented as string that contains all non-empty properties separated by `, `.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$bank = new BankAccount('Bank of America', '1234567890');
|
||||||
|
$asString = (string)$bank; // "Bank of America, 1234567890"
|
||||||
|
```
|
||||||
|
|
||||||
### Version
|
### Version
|
||||||
|
|
||||||
##### Namespace
|
##### Namespace
|
||||||
|
|||||||
81
src/ValueObject/BankAccount.php
Normal file
81
src/ValueObject/BankAccount.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\ValueObject;
|
||||||
|
|
||||||
|
use Meritoo\Common\Utilities\Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bank account
|
||||||
|
*
|
||||||
|
* @author Meritoo <github@meritoo.pl>
|
||||||
|
* @copyright Meritoo <http://www.meritoo.pl>
|
||||||
|
*/
|
||||||
|
class BankAccount
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Name of bank
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $bankName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of bank's account
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $accountNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*
|
||||||
|
* @param string $bankName Name of bank
|
||||||
|
* @param string $accountNumber Number of bank's account
|
||||||
|
*/
|
||||||
|
public function __construct($bankName, $accountNumber)
|
||||||
|
{
|
||||||
|
$this->bankName = $bankName;
|
||||||
|
$this->accountNumber = $accountNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns representation of object as string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
$values = [
|
||||||
|
$this->bankName,
|
||||||
|
$this->accountNumber,
|
||||||
|
];
|
||||||
|
|
||||||
|
return Arrays::getNonEmptyValuesAsString($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns name of bank
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBankName()
|
||||||
|
{
|
||||||
|
return $this->bankName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns number of bank's account
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAccountNumber()
|
||||||
|
{
|
||||||
|
return $this->accountNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
71
tests/ValueObject/BankAccountTest.php
Normal file
71
tests/ValueObject/BankAccountTest.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\ValueObject;
|
||||||
|
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
|
use Meritoo\Common\ValueObject\BankAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for the bank account
|
||||||
|
*
|
||||||
|
* @author Meritoo <github@meritoo.pl>
|
||||||
|
* @copyright Meritoo <http://www.meritoo.pl>
|
||||||
|
*/
|
||||||
|
class BankAccountTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var BankAccount
|
||||||
|
*/
|
||||||
|
private $emptyBankAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BankAccount
|
||||||
|
*/
|
||||||
|
private $bankAccount;
|
||||||
|
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
|
static::assertConstructorVisibilityAndArguments(
|
||||||
|
BankAccount::class,
|
||||||
|
OopVisibilityType::IS_PUBLIC,
|
||||||
|
2,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAccountNumber()
|
||||||
|
{
|
||||||
|
self::assertSame('', $this->emptyBankAccount->getAccountNumber());
|
||||||
|
self::assertSame('1234567890', $this->bankAccount->getAccountNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetBankName()
|
||||||
|
{
|
||||||
|
self::assertSame('', $this->emptyBankAccount->getBankName());
|
||||||
|
self::assertSame('Bank of America', $this->bankAccount->getBankName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToString()
|
||||||
|
{
|
||||||
|
static::assertSame('', (string)$this->emptyBankAccount);
|
||||||
|
static::assertSame('Bank of America, 1234567890', (string)$this->bankAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->emptyBankAccount = new BankAccount('', '');
|
||||||
|
$this->bankAccount = new BankAccount('Bank of America', '1234567890');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user