| Conditions | 1 |
| Paths | 1 |
| Total Lines | 66 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 20 | public function testExportAccountingReport(): void |
||
| 21 | { |
||
| 22 | $this->setCurrentUser('responsible'); |
||
| 23 | |||
| 24 | $hostname = 'my-ichtus.lan'; |
||
| 25 | |||
| 26 | $accountingConfig = [ |
||
| 27 | 'salesAccountCode' => 3200, |
||
| 28 | 'bankAccountCode' => 1020, |
||
| 29 | 'customerDepositsAccountCode' => 2030, |
||
| 30 | 'report' => [ |
||
| 31 | 'showAccountsWithZeroBalance' => true, |
||
| 32 | 'maxAccountDepth' => 2, |
||
| 33 | 'accountClasses' => [ |
||
| 34 | 'assets' => ['1'], |
||
| 35 | 'liabilities' => ['2'], |
||
| 36 | 'revenues' => ['3'], |
||
| 37 | 'expenses' => ['4', '5', '6'], |
||
| 38 | 'equity' => ['7', '8', '9'], |
||
| 39 | ], |
||
| 40 | ], |
||
| 41 | ]; |
||
| 42 | |||
| 43 | // Query to generate the Excel file on disk |
||
| 44 | /** @var AccountRepository $repository */ |
||
| 45 | $repository = _em()->getRepository(Account::class); |
||
| 46 | $query = $repository->getRootAccountsQuery(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * TEST REPORT WITH BALANCE AT SELECTED DATE. |
||
| 50 | */ |
||
| 51 | $handler = new AccountingReport($hostname, $accountingConfig); |
||
| 52 | $handler->setDate(new ChronosDate('2019-12-31')); |
||
| 53 | $url = $handler->export($query->getResult()); |
||
| 54 | |||
| 55 | $spreadsheet = $this->readExport($hostname, $url); |
||
| 56 | $sheet = $spreadsheet->getActiveSheet(); |
||
| 57 | |||
| 58 | // Test a few arbitrary data |
||
| 59 | self::assertSame('my-ichtus.lan: rapport comptable au 31.12.2019', $sheet->getCell('A1')->getCalculatedValue()); |
||
| 60 | self::assertSame('Actifs', $sheet->getCell('A3')->getCalculatedValue()); |
||
| 61 | self::assertSame('Passifs', $sheet->getCell('E3')->getCalculatedValue()); |
||
| 62 | self::assertSame('Charges', $sheet->getCell('A25')->getCalculatedValue()); |
||
| 63 | self::assertSame('Profits', $sheet->getCell('E25')->getCalculatedValue()); |
||
| 64 | self::assertSame(35187.50, $sheet->getCell('C5')->getCalculatedValue()); |
||
| 65 | self::assertSame(240.0, $sheet->getCell('C70')->getCalculatedValue()); |
||
| 66 | |||
| 67 | /** |
||
| 68 | * TEST REPORT WITH BALANCE AT SELECTED DATE + BUDGET COLUMNS. |
||
| 69 | */ |
||
| 70 | $handler = new AccountingReport($hostname, $accountingConfig); |
||
| 71 | $handler->setDate(new ChronosDate('2019-12-31')); |
||
| 72 | $handler->showBudget(true); |
||
| 73 | $handler->setDatePrevious(new ChronosDate('2018-12-31')); |
||
| 74 | $url = $handler->export($query->getResult()); |
||
| 75 | |||
| 76 | $spreadsheet = $this->readExport($hostname, $url); |
||
| 77 | $sheet = $spreadsheet->getActiveSheet(); |
||
| 78 | |||
| 79 | // Tests data from budget columns |
||
| 80 | self::assertSame('31.12.2018', $sheet->getCell('D4')->getCalculatedValue(), 'assets, headers, previous balance'); |
||
| 81 | self::assertSame('Budget prévu', $sheet->getCell('E4')->getCalculatedValue(), 'assets, headers, budget allowed'); |
||
| 82 | self::assertSame('Budget restant', $sheet->getCell('M4')->getCalculatedValue(), 'liabilities, headers, budget balance'); |
||
| 83 | self::assertSame(500.00, $sheet->getCell('E12')->getCalculatedValue(), '1500 machines budget allowed'); |
||
| 84 | self::assertSame(500.00, $sheet->getCell('F12')->getCalculatedValue(), '1500 machines leftover balance'); |
||
| 85 | self::assertSame(87.50, $sheet->getCell('F54')->getCalculatedValue(), '6500 admin leftover budget'); |
||
| 86 | } |
||
| 88 |