2018-09-21 01:27:56 +02:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2019-06-07 22:48:39 +02:00
|
|
|
namespace App\Tests\Invoice\NumberGenerator;
|
2018-09-21 01:27:56 +02:00
|
|
|
|
2023-07-26 15:16:59 +02:00
|
|
|
use App\Entity\Customer;
|
|
|
|
use App\Entity\InvoiceTemplate;
|
2018-09-21 01:27:56 +02:00
|
|
|
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
2021-03-14 13:53:36 +01:00
|
|
|
use App\Repository\InvoiceRepository;
|
2023-07-26 15:16:59 +02:00
|
|
|
use App\Repository\Query\InvoiceQuery;
|
2019-12-02 10:57:03 +01:00
|
|
|
use App\Tests\Invoice\DebugFormatter;
|
2021-12-08 22:15:07 +01:00
|
|
|
use App\Tests\Mocks\InvoiceModelFactoryFactory;
|
2018-09-21 01:27:56 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \App\Invoice\NumberGenerator\DateNumberGenerator
|
|
|
|
*/
|
|
|
|
class DateNumberGeneratorTest extends TestCase
|
|
|
|
{
|
2021-03-14 13:53:36 +01:00
|
|
|
private function getSut(bool $hasInitialInvoice, bool $followingInvoices)
|
|
|
|
{
|
|
|
|
$repository = $this->createMock(InvoiceRepository::class);
|
|
|
|
$repository
|
|
|
|
->expects($this->any())
|
|
|
|
->method('hasInvoice')
|
|
|
|
->willReturnCallback(function ($number) use ($hasInitialInvoice, $followingInvoices) {
|
|
|
|
if (stripos($number, '-') === false) {
|
|
|
|
return $hasInitialInvoice;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $followingInvoices;
|
|
|
|
});
|
|
|
|
|
|
|
|
return new DateNumberGenerator($repository);
|
|
|
|
}
|
|
|
|
|
2024-02-07 23:47:25 +01:00
|
|
|
public function testGetInvoiceNumber(): void
|
2018-09-21 01:27:56 +02:00
|
|
|
{
|
2021-03-14 13:53:36 +01:00
|
|
|
$sut = $this->getSut(false, false);
|
2023-07-26 15:16:59 +02:00
|
|
|
$sut->setModel((new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter(), new Customer('foo'), new InvoiceTemplate(), new InvoiceQuery()));
|
2018-09-21 01:27:56 +02:00
|
|
|
|
2024-12-22 01:25:30 +01:00
|
|
|
self::assertEquals(date('ymd'), $sut->getInvoiceNumber());
|
|
|
|
self::assertEquals('date', $sut->getId());
|
2018-09-21 01:27:56 +02:00
|
|
|
}
|
2021-03-14 13:53:36 +01:00
|
|
|
|
2024-02-07 23:47:25 +01:00
|
|
|
public function testGetInvoiceNumberWithExisting(): void
|
2021-03-14 13:53:36 +01:00
|
|
|
{
|
|
|
|
$sut = $this->getSut(true, false);
|
2023-07-26 15:16:59 +02:00
|
|
|
$sut->setModel((new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter(), new Customer('foo'), new InvoiceTemplate(), new InvoiceQuery()));
|
2021-03-14 13:53:36 +01:00
|
|
|
|
2024-12-22 01:25:30 +01:00
|
|
|
self::assertEquals(date('ymd-01'), $sut->getInvoiceNumber());
|
|
|
|
self::assertEquals('date', $sut->getId());
|
2021-03-14 13:53:36 +01:00
|
|
|
}
|
|
|
|
|
2024-02-07 23:47:25 +01:00
|
|
|
public function testGetInvoiceNumberWithManyExisting(): void
|
2021-03-14 13:53:36 +01:00
|
|
|
{
|
|
|
|
$sut = $this->getSut(true, true);
|
2023-07-26 15:16:59 +02:00
|
|
|
$sut->setModel((new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter(), new Customer('foo'), new InvoiceTemplate(), new InvoiceQuery()));
|
2021-03-14 13:53:36 +01:00
|
|
|
|
2024-12-22 01:25:30 +01:00
|
|
|
self::assertEquals(date('ymd-99'), $sut->getInvoiceNumber());
|
|
|
|
self::assertEquals('date', $sut->getId());
|
2021-03-14 13:53:36 +01:00
|
|
|
}
|
2018-09-21 01:27:56 +02:00
|
|
|
}
|