ValueObject > BankAccount > represents bank account

This commit is contained in:
Meritoo
2019-02-22 20:37:16 +01:00
parent 0c7e27b884
commit 07a04d86f0
3 changed files with 187 additions and 0 deletions

View File

@@ -57,6 +57,41 @@ $address = new Address('New York', '00123', '4th Avenue', '10', '200');
$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
##### Namespace

View 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;
}
}

View 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');
}
}