Release 2.57 (#5929)
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user