Files
kimai/tests/Invoice/Hydrator/InvoiceModelDefaultHydratorTest.php
Kevin Papst 677f8d776c [3.0] Update Symfony to 7.4 and dependencies, removed deprecated code, removed API password (#5622)
* deactivate deprecated auto-mapping
* use native month-picker with fallback on old browser
* bump dependencies to new major versions
* replace deprecated ARRAY column type with JSON
* named arguments
* nullable arguments
* native lazy ghosts
* update routes to use php config
* disable PHP < 8.4
* use static RTL configuration
* new qr code package
* clear out env file
* recipe updates
* fix deprecations
* preset new env variable if not existing
* bump maria db version examples
* remove deprecated api-token support
* fix validator deprecations
* remove timesheet category column
* fix broken validator autoconfiguration
* stabilize tests
* fix migration syntax compatibility
* fix doctrine deprecation
* fix datetime format
* remove constructor dependency
* only include visible preferences in invoice templates
* fix test container dependency
* removed ProjectConstraint multi-constraint logic
* allow to disable plugins in certain environments
* refactor TimesheetConstraint to non-service
* activate new interface methods
* prevent update issues with .env
* improved customer fixture
* removed $user->isExportDecimal()
2026-01-04 15:04:25 +01:00

115 lines
3.2 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Invoice\Hydrator;
use App\Invoice\Hydrator\InvoiceModelDefaultHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use ReflectionObject;
#[CoversClass(InvoiceModelDefaultHydrator::class)]
class InvoiceModelDefaultHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate(): void
{
$model = $this->getInvoiceModel();
$sut = new InvoiceModelDefaultHydrator();
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
}
public function testHydrateThrowsOnMissing(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('InvoiceModel needs a calculator');
$model = $this->getInvoiceModel();
$obj = new ReflectionObject($model);
$prop = $obj->getProperty('calculator');
$prop->setValue($model, null);
$sut = new InvoiceModelDefaultHydrator();
$sut->hydrate($model);
}
protected function assertModelStructure(array $model, bool $hasProject = true): void
{
$keys = [
'invoice.due_date',
'invoice.due_date_process',
'invoice.date',
'invoice.date_process',
'invoice.number',
'invoice.currency',
'invoice.currency_symbol',
'invoice.vat',
'invoice.language',
'invoice.tax',
'invoice.tax_hide',
'invoice.tax_nc',
'invoice.tax_plain',
'invoice.tax_rows',
'invoice.total_time',
'invoice.duration_decimal',
'invoice.first',
'invoice.first_process',
'invoice.last',
'invoice.last_process',
'invoice.total',
'invoice.total_nc',
'invoice.total_plain',
'invoice.subtotal',
'invoice.subtotal_nc',
'invoice.subtotal_plain',
'template.name',
'template.company',
'template.country',
'template.country_name',
'template.address',
'template.title',
'template.payment_terms',
'template.due_days',
'template.vat_id',
'template.contact',
'template.payment_details',
'query.day',
'query.month',
'query.month_number',
'query.year',
'query.begin',
'query.begin_process',
'query.begin_day',
'query.begin_month',
'query.begin_month_number',
'query.begin_year',
'query.end',
'query.end_process',
'query.end_day',
'query.end_month',
'query.end_month_number',
'query.end_year',
'user.see_others',
];
$givenKeys = array_keys($model);
sort($keys);
sort($givenKeys);
self::assertEquals($keys, $givenKeys);
}
}