|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\Account; |
|
8
|
|
|
use Application\Model\Transaction; |
|
9
|
|
|
use Application\Model\User; |
|
10
|
|
|
use Doctrine\DBAL\Exception\InvalidArgumentException; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class AccountTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testUserRelation(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$account = new Account(); |
|
18
|
|
|
self::assertNull($account->getOwner()); |
|
19
|
|
|
|
|
20
|
|
|
$user = new User(); |
|
21
|
|
|
User::setCurrent($user); |
|
22
|
|
|
$account->setOwner($user); |
|
23
|
|
|
|
|
24
|
|
|
self::assertSame($account->getOwner(), $user); |
|
25
|
|
|
self::assertSame($account, $user->getAccount()); |
|
26
|
|
|
|
|
27
|
|
|
$otherUser = new User(); |
|
28
|
|
|
$account->setOwner($otherUser); |
|
29
|
|
|
self::assertSame($otherUser, $account->getOwner(), 'Account must have second user'); |
|
30
|
|
|
self::assertNull($user->getAccount(), 'First user must have no account'); |
|
31
|
|
|
self::assertSame($account, $otherUser->getAccount(), 'second user must have account'); |
|
32
|
|
|
|
|
33
|
|
|
User::setCurrent($otherUser); |
|
34
|
|
|
$account->setOwner(null); |
|
35
|
|
|
self::assertNull($account->getOwner(), 'Account must have no user'); |
|
36
|
|
|
self::assertNull($user->getAccount(), 'First user must have no account'); |
|
37
|
|
|
self::assertNull($otherUser->getAccount(), 'Second user must have no account'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testTransactionRelation(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$account = new Account(); |
|
43
|
|
|
|
|
44
|
|
|
$transaction = new Transaction(); |
|
45
|
|
|
$transaction->setAccount($account); |
|
46
|
|
|
|
|
47
|
|
|
self::assertCount(1, $account->getTransactions(), 'Account must have 1 transaction'); |
|
48
|
|
|
|
|
49
|
|
|
$otherAccount = new Account(); |
|
50
|
|
|
$transaction->setAccount($otherAccount); |
|
51
|
|
|
|
|
52
|
|
|
self::assertCount(0, $account->getTransactions(), 'Original account without transaction'); |
|
53
|
|
|
|
|
54
|
|
|
self::assertSame($transaction->getAccount(), $otherAccount); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testIban(): void |
|
58
|
|
|
{ |
|
59
|
|
|
$account = new Account(); |
|
60
|
|
|
|
|
61
|
|
|
self::assertEmpty($account->getIban()); |
|
62
|
|
|
|
|
63
|
|
|
$iban = 'CH6303714697192579556'; |
|
64
|
|
|
$account->setIban($iban); |
|
65
|
|
|
self::assertSame($iban, $account->getIban()); |
|
66
|
|
|
|
|
67
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
68
|
|
|
$invalidIban = 'CH123456789012345678'; |
|
69
|
|
|
$account->setIban($invalidIban); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|