|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\TransactionLine; |
|
8
|
|
|
use Application\Repository\TransactionLineRepository; |
|
9
|
|
|
use ApplicationTest\Traits\LimitedAccessSubQuery; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @group Repository |
|
13
|
|
|
*/ |
|
14
|
|
|
class TransactionLineRepositoryTest extends AbstractRepositoryTest |
|
15
|
|
|
{ |
|
16
|
|
|
use LimitedAccessSubQuery; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var TransactionLineRepository |
|
20
|
|
|
*/ |
|
21
|
|
|
private $repository; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
$this->repository = $this->getEntityManager()->getRepository(TransactionLine::class); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function providerGetAccessibleSubQuery(): array |
|
30
|
|
|
{ |
|
31
|
|
|
$all = range(14000, 14011); |
|
32
|
|
|
|
|
33
|
|
|
$family = [14000, 14002, 14003, 14004, 14008, 14011]; |
|
34
|
|
|
|
|
35
|
|
|
return [ |
|
36
|
|
|
['anonymous', []], |
|
37
|
|
|
['bookingonly', []], |
|
38
|
|
|
['individual', $family], |
|
39
|
|
|
['member', $family], |
|
40
|
|
|
['responsible', $all], |
|
41
|
|
|
['administrator', $all], |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testTriggers(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$account1 = 10096; |
|
48
|
|
|
$account2 = 10037; |
|
49
|
|
|
$account3 = 10085; |
|
50
|
|
|
$account4 = 10025; |
|
51
|
|
|
|
|
52
|
|
|
$this->assertAccountBalance($account1, 5000, 'initial balance'); |
|
53
|
|
|
$this->assertAccountBalance($account2, 10000, 'initial balance'); |
|
54
|
|
|
$this->assertAccountBalance($account3, 1250, 'initial balance'); |
|
55
|
|
|
$this->assertAccountBalance($account4, 818750, 'initial balance'); |
|
56
|
|
|
|
|
57
|
|
|
$connection = $this->getEntityManager()->getConnection(); |
|
58
|
|
|
$connection->insert('transaction_line', [ |
|
59
|
|
|
'transaction_id' => 8000, |
|
60
|
|
|
'debit_id' => $account1, |
|
61
|
|
|
'credit_id' => $account2, |
|
62
|
|
|
'balance' => 500, |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
|
|
$id = $connection->lastInsertId(); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertAccountBalance($account1, 4500, 'balance should be reduced when line is inserted'); |
|
68
|
|
|
$this->assertAccountBalance($account2, 10500, 'balance should be increased when line is inserted'); |
|
69
|
|
|
|
|
70
|
|
|
$count = $connection->update('transaction_line', |
|
71
|
|
|
[ |
|
72
|
|
|
'balance' => 4000, |
|
73
|
|
|
], |
|
74
|
|
|
[ |
|
75
|
|
|
'id' => $id, |
|
76
|
|
|
] |
|
77
|
|
|
); |
|
78
|
|
|
self::assertSame(1, $count); |
|
79
|
|
|
$this->assertAccountBalance($account1, 1000, 'balance should be reduced even more after update'); |
|
80
|
|
|
$this->assertAccountBalance($account2, 14000, 'balance should be increased even more after update'); |
|
81
|
|
|
|
|
82
|
|
|
$count = $connection->update('transaction_line', |
|
83
|
|
|
[ |
|
84
|
|
|
'debit_id' => $account3, |
|
85
|
|
|
'credit_id' => $account4, |
|
86
|
|
|
], |
|
87
|
|
|
[ |
|
88
|
|
|
'id' => $id, |
|
89
|
|
|
] |
|
90
|
|
|
); |
|
91
|
|
|
self::assertSame(1, $count); |
|
92
|
|
|
$this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion'); |
|
93
|
|
|
$this->assertAccountBalance($account2, 10000, 'balance should be restored to its original value after deletion'); |
|
94
|
|
|
$this->assertAccountBalance($account3, 5250, 'balance should be increased after swapped account'); |
|
95
|
|
|
$this->assertAccountBalance($account4, 814750, 'balance should be reduced after swapped account'); |
|
96
|
|
|
|
|
97
|
|
|
$count = $connection->delete('transaction_line', ['id' => $id]); |
|
98
|
|
|
self::assertSame(1, $count); |
|
99
|
|
|
$this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion'); |
|
100
|
|
|
$this->assertAccountBalance($account2, 10000, 'balance should be restored to its original value after deletion'); |
|
101
|
|
|
$this->assertAccountBalance($account3, 1250, 'balance should be restored to its original value after deletion'); |
|
102
|
|
|
$this->assertAccountBalance($account4, 818750, 'balance should be restored to its original value after deletion'); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|