Passed
Push — master ( 048cfc...89074f )
by
unknown
12:32
created

AccountTest::testTransactionRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 15
rs 10
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\Transaction;
9
use Application\Model\User;
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->getUser());
18
19
        $user = new User();
20
        $account->setUser($user);
21
22
        self::assertSame($account->getUser(), $user);
23
        self::assertSame($account, $user->getAccount());
24
25
        $otherUser = new User();
26
        $account->setUser($otherUser);
27
        self::assertNull($user->getAccount(), 'First user must have no account');
28
29
        $account->setUser(null);
30
        self::assertNull($account->getUser(), 'Account must have no user');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $account->getUser() targeting Application\Model\Account::getUser() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
31
        self::assertNull($user->getAccount(), 'User must have no account');
32
    }
33
34
    public function testTransactionRelation(): void
35
    {
36
        $account = new Account();
37
38
        $transaction = new Transaction();
39
        $transaction->setAccount($account);
40
41
        self::assertCount(1, $account->getTransactions(), 'Account must have 1 transaction');
42
43
        $otherAccount = new Account();
44
        $transaction->setAccount($otherAccount);
45
46
        self::assertCount(0, $account->getTransactions(), 'Original account without transaction');
47
48
        self::assertSame($transaction->getAccount(), $otherAccount);
49
    }
50
}
51