|
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'); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
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.