1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Service; |
6
|
|
|
|
7
|
|
|
use Application\Enum\AccountType; |
8
|
|
|
use Application\Model\Account; |
9
|
|
|
use Application\Repository\AccountRepository; |
10
|
|
|
use Application\Service\Accounting; |
11
|
|
|
use ApplicationTest\Traits\TestWithTransactionAndUser; |
12
|
|
|
use Cake\Chronos\Chronos; |
13
|
|
|
use Cake\Chronos\ChronosDate; |
14
|
|
|
use Money\Money; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class AccountingTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
use TestWithTransactionAndUser { |
20
|
|
|
setUp as setupWithTransaction; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
private Accounting $accounting; |
24
|
|
|
|
25
|
|
|
protected function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->setupWithTransaction(); |
28
|
|
|
|
29
|
|
|
$this->setCurrentUser('administrator'); |
30
|
|
|
|
31
|
|
|
global $container; |
32
|
|
|
$this->accounting = $container->get(Accounting::class); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCheck(): void |
36
|
|
|
{ |
37
|
|
|
$this->expectOutputString( |
38
|
|
|
<<<STRING |
39
|
|
|
|
40
|
|
|
Produits : 240.00 |
41
|
|
|
Charges : 112.50 |
42
|
|
|
Bénéfice : 127.50 |
43
|
|
|
Actifs : 35187.50 |
44
|
|
|
Passifs : 60.00 |
45
|
|
|
Capital : 35000.00 |
46
|
|
|
Écart : 0.00 |
47
|
|
|
Création du compte 20300010 pour l'utilisateur 1003... |
48
|
|
|
Création du compte 20300011 pour l'utilisateur 1004... |
49
|
|
|
Création du compte 20300012 pour l'utilisateur 1005... |
50
|
|
|
Création du compte 20300013 pour l'utilisateur 1006... |
51
|
|
|
Création du compte 20300014 pour l'utilisateur 1014... |
52
|
|
|
Création du compte 20300015 pour l'utilisateur 1015... |
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 = ChronosDate::create(2019, 12, 31); |
65
|
|
|
|
66
|
|
|
$expectedLog = [ |
67
|
|
|
'Bouclement au 31.12.2019', |
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
|
|
|
$expectedDateTime = new Chronos('2020-01-01 00:00:00'); |
76
|
|
|
self::assertTrue($actualDate->equals($expectedDateTime), 'Closing transaction was not created on ' . $closingDate); |
77
|
|
|
|
78
|
|
|
$accounts = $accountRepository->findByType([AccountType::Revenue, AccountType::Expense]); |
|
|
|
|
79
|
|
|
$openingDate = $closingDate->addDays(1); |
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'); |
85
|
|
|
$this->accounting->close($closingDate, $output); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|