Release 2.57 (#5929)
This commit is contained in:
@@ -28,6 +28,22 @@ class InvoiceModelDefaultHydratorTest extends TestCase
|
||||
|
||||
$result = $sut->hydrate($model);
|
||||
$this->assertModelStructure($result);
|
||||
self::assertSame(
|
||||
$model->getFormatter()->getFormattedDateTime($model->getInvoicePeriod()->getStart()),
|
||||
$result['invoice.first']
|
||||
);
|
||||
self::assertSame(
|
||||
$model->getInvoicePeriod()->getStart()->format('Y-m-d h:i:s'),
|
||||
$result['invoice.first_process']
|
||||
);
|
||||
self::assertSame(
|
||||
$model->getFormatter()->getFormattedDateTime($model->getInvoicePeriod()->getEnd()),
|
||||
$result['invoice.last']
|
||||
);
|
||||
self::assertSame(
|
||||
$model->getInvoicePeriod()->getEnd()->format('Y-m-d h:i:s'),
|
||||
$result['invoice.last_process']
|
||||
);
|
||||
}
|
||||
|
||||
public function testHydrateThrowsOnMissing(): void
|
||||
@@ -67,8 +83,12 @@ class InvoiceModelDefaultHydratorTest extends TestCase
|
||||
'invoice.total_time',
|
||||
'invoice.duration_decimal',
|
||||
'invoice.first',
|
||||
'invoice.first_month',
|
||||
'invoice.first_year',
|
||||
'invoice.first_process',
|
||||
'invoice.last',
|
||||
'invoice.last_month',
|
||||
'invoice.last_year',
|
||||
'invoice.last_process',
|
||||
'invoice.total',
|
||||
'invoice.total_nc',
|
||||
|
||||
@@ -33,6 +33,7 @@ class InvoiceModelProjectHydratorTest extends TestCase
|
||||
public function assertModelStructure(array $model): void
|
||||
{
|
||||
$keys = [
|
||||
'project._counter',
|
||||
'project.id',
|
||||
'project.name',
|
||||
'project.comment',
|
||||
|
||||
@@ -13,15 +13,21 @@ use App\Entity\Customer;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Invoice\InvoiceModel;
|
||||
use App\Invoice\InvoicePeriod;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use App\Tests\Invoice\NumberGenerator\IncrementingNumberGenerator;
|
||||
use App\Tests\Invoice\Renderer\RendererTestTrait;
|
||||
use App\Tests\Mocks\InvoiceModelFactoryFactory;
|
||||
use App\Timesheet\RateCalculator\DecimalRateCalculator;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(InvoiceModel::class)]
|
||||
#[CoversClass(InvoicePeriod::class)]
|
||||
class InvoiceModelTest extends TestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function testEmptyObject(): void
|
||||
{
|
||||
$formatter = new DebugFormatter();
|
||||
@@ -119,4 +125,50 @@ class InvoiceModelTest extends TestCase
|
||||
$expected = new \DateTimeImmutable('2022-06-06');
|
||||
self::assertEquals($expected->format('Y-m-d'), $dueDate->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testGetInvoicePeriod(): void
|
||||
{
|
||||
$sut = $this->getInvoiceModel();
|
||||
|
||||
$period = $sut->getInvoicePeriod();
|
||||
|
||||
self::assertSame('2020-08-12 18:00:00', $period->getStart()->format('Y-m-d H:i:s'));
|
||||
self::assertSame('2021-03-12 12:17:40', $period->getEnd()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function testGetInvoicePeriodFallsBackToQueryDates(): void
|
||||
{
|
||||
$query = new InvoiceQuery();
|
||||
$query->setBegin(new \DateTime('2022-01-02 03:04:05'));
|
||||
$query->setEnd(new \DateTime('2022-06-07 08:09:10'));
|
||||
|
||||
$sut = (new InvoiceModelFactoryFactory($this))->create()->createModel(
|
||||
new DebugFormatter(),
|
||||
new Customer('foo'),
|
||||
new InvoiceTemplate(),
|
||||
$query
|
||||
);
|
||||
|
||||
$period = $sut->getInvoicePeriod();
|
||||
|
||||
self::assertSame('2022-01-02 00:00:00', $period->getStart()->format('Y-m-d H:i:s'));
|
||||
self::assertSame('2022-06-07 23:59:59', $period->getEnd()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function testGetInvoicePeriodFallsBackToInvoiceDateWithoutQuery(): void
|
||||
{
|
||||
$invoiceDate = new \DateTimeImmutable('2023-09-10 11:12:13');
|
||||
$sut = new InvoiceModel(
|
||||
new DebugFormatter(),
|
||||
new Customer('foo'),
|
||||
new InvoiceTemplate(),
|
||||
new DecimalRateCalculator()
|
||||
);
|
||||
$sut->setInvoiceDate($invoiceDate);
|
||||
|
||||
$period = $sut->getInvoicePeriod();
|
||||
|
||||
self::assertSame('2023-09-10 11:12:13', $period->getStart()->format('Y-m-d H:i:s'));
|
||||
self::assertSame('2023-09-10 11:12:13', $period->getEnd()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
|
||||
29
tests/Invoice/InvoicePeriodTest.php
Normal file
29
tests/Invoice/InvoicePeriodTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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;
|
||||
|
||||
use App\Invoice\InvoicePeriod;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(InvoicePeriod::class)]
|
||||
class InvoicePeriodTest extends TestCase
|
||||
{
|
||||
public function testGetters(): void
|
||||
{
|
||||
$start = new \DateTimeImmutable('2024-01-02 03:04:05');
|
||||
$end = new \DateTimeImmutable('2024-06-07 08:09:10');
|
||||
|
||||
$sut = new InvoicePeriod($start, $end);
|
||||
|
||||
self::assertSame($start, $sut->getStart());
|
||||
self::assertSame($end, $sut->getEnd());
|
||||
}
|
||||
}
|
||||
@@ -104,8 +104,12 @@ class DebugRendererTest extends TestCase
|
||||
'invoice.total_time',
|
||||
'invoice.duration_decimal',
|
||||
'invoice.first',
|
||||
'invoice.first_month',
|
||||
'invoice.first_year',
|
||||
'invoice.first_process',
|
||||
'invoice.last',
|
||||
'invoice.last_month',
|
||||
'invoice.last_year',
|
||||
'invoice.last_process',
|
||||
'invoice.total',
|
||||
'invoice.total_nc',
|
||||
@@ -210,6 +214,7 @@ class DebugRendererTest extends TestCase
|
||||
'user.meta.hello',
|
||||
'user.meta.kitty',
|
||||
'testFromModelHydrator',
|
||||
'project._counter',
|
||||
];
|
||||
|
||||
if ($activityCounter === 1) {
|
||||
|
||||
Reference in New Issue
Block a user