1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Service; |
6
|
|
|
|
7
|
|
|
use Application\DBAL\Types\AccountTypeType; |
8
|
|
|
use Application\Model\Account; |
9
|
|
|
use Application\Model\User; |
10
|
|
|
use Application\Repository\AccountRepository; |
11
|
|
|
use Application\Service\Accounting; |
12
|
|
|
use ApplicationTest\Traits\TestWithTransactionAndUser; |
13
|
|
|
use Cake\Chronos\Chronos; |
14
|
|
|
use Cake\Chronos\Date; |
15
|
|
|
use Money\Money; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
class AccountingTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use TestWithTransactionAndUser { |
21
|
|
|
setUp as setupWithTransaction; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
private Accounting $accounting; |
25
|
|
|
|
26
|
|
|
protected function setUp(): void |
27
|
|
|
{ |
28
|
|
|
$this->setupWithTransaction(); |
29
|
|
|
|
30
|
|
|
/** @var User $user */ |
31
|
|
|
$user = _em()->getRepository(User::class)->getOneByLogin('administrator'); |
32
|
|
|
User::setCurrent($user); |
33
|
|
|
|
34
|
|
|
global $container; |
35
|
|
|
$this->accounting = $container->get(Accounting::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCheck(): void |
39
|
|
|
{ |
40
|
|
|
$this->expectOutputString(<<<STRING |
41
|
|
|
|
42
|
|
|
Produits : 240.00 |
43
|
|
|
Charges : 112.50 |
44
|
|
|
Bénéfice : 127.50 |
45
|
|
|
Actifs : 35187.50 |
46
|
|
|
Passifs : 60.00 |
47
|
|
|
Capital : 35000.00 |
48
|
|
|
Écart : 0.00 |
49
|
|
|
Création du compte 20300010 pour l'utilisateur 1003... |
50
|
|
|
Création du compte 20300011 pour l'utilisateur 1004... |
51
|
|
|
Création du compte 20300012 pour l'utilisateur 1005... |
52
|
|
|
Création du compte 20300013 pour l'utilisateur 1006... |
53
|
|
|
|
54
|
|
|
STRING |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
self::assertFalse($this->accounting->check(), 'fixture data should not produce any errors'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testClose(): void |
61
|
|
|
{ |
62
|
|
|
/** @var AccountRepository $accountRepository */ |
63
|
|
|
$accountRepository = _em()->getRepository(Account::class); |
64
|
|
|
$closingDate = Date::createFromDate(2019, 12, 31); |
65
|
|
|
|
66
|
|
|
$expectedLog = [ |
67
|
|
|
'Bouclement au 2019-12-31', |
68
|
|
|
'Bénéfice : 127.50', |
69
|
|
|
]; |
70
|
|
|
$output = []; |
71
|
|
|
$closingTransaction = $this->accounting->close($closingDate, $output); |
72
|
|
|
self::assertSame($expectedLog, $output); |
73
|
|
|
|
74
|
|
|
$actualDate = $closingTransaction->getTransactionDate(); |
75
|
|
|
$expectedDate = (new Chronos($closingDate))->endOfDay(); |
76
|
|
|
self::assertTrue($actualDate->eq($expectedDate), 'Closing transaction was not created on ' . $closingDate); |
77
|
|
|
|
78
|
|
|
$accounts = $accountRepository->findByType([AccountTypeType::REVENUE, AccountTypeType::EXPENSE]); |
|
|
|
|
79
|
|
|
$openingDate = $closingDate->addDay(); |
80
|
|
|
foreach ($accounts as $account) { |
81
|
|
|
self::assertTrue(Money::CHF(0)->equals($account->getBalanceAtDate($openingDate))); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->expectExceptionMessage('Le bouclement a déjà été fait au 2019-12-31 23:59:59'); |
85
|
|
|
$this->accounting->close($closingDate, $output); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|