Failed Conditions
Push — master ( 5fbadf...673c47 )
by Adrien
07:14
created

AccountTest::testUserRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

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