added command to create invoices via bash (#1574)
This commit is contained in:
@@ -47,6 +47,10 @@ class InvoiceModelCustomerHydratorTest extends TestCase
|
||||
'customer.number',
|
||||
'customer.homepage',
|
||||
'customer.comment',
|
||||
'customer.email',
|
||||
'customer.fax',
|
||||
'customer.phone',
|
||||
'customer.mobile',
|
||||
'customer.meta.foo-customer',
|
||||
];
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Invoice\InvoiceModel;
|
||||
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use App\Tests\Invoice\NumberGenerator\IncrementingNumberGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,16 @@ class InvoiceModelTest extends TestCase
|
||||
self::assertSame($formatter, $sut->getFormatter());
|
||||
}
|
||||
|
||||
public function testEmptyObjectThrowsExceptionOnNumberGenerator()
|
||||
{
|
||||
$formatter = new DebugFormatter();
|
||||
$sut = new InvoiceModel($formatter);
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('InvoiceModel::getInvoiceNumber() cannot be called before calling setNumberGenerator()');
|
||||
$sut->getInvoiceNumber();
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new InvoiceModel(new DebugFormatter());
|
||||
@@ -59,9 +69,14 @@ class InvoiceModelTest extends TestCase
|
||||
self::assertInstanceOf(InvoiceModel::class, $sut->setCalculator($calculator));
|
||||
self::assertSame($calculator, $sut->getCalculator());
|
||||
|
||||
$generator = new DateNumberGenerator();
|
||||
$generator = new IncrementingNumberGenerator();
|
||||
self::assertInstanceOf(InvoiceModel::class, $sut->setNumberGenerator($generator));
|
||||
self::assertSame($generator, $sut->getNumberGenerator());
|
||||
$number = $sut->getInvoiceNumber();
|
||||
$first = $sut->getNumberGenerator()->getInvoiceNumber();
|
||||
$second = $sut->getNumberGenerator()->getInvoiceNumber();
|
||||
self::assertEquals(((int) $first + 1), $second);
|
||||
self::assertEquals($number, $sut->getInvoiceNumber());
|
||||
|
||||
$template = new InvoiceTemplate();
|
||||
self::assertNull($sut->getDueDate());
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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\NumberGenerator;
|
||||
|
||||
use App\Invoice\InvoiceModel;
|
||||
use App\Invoice\NumberGeneratorInterface;
|
||||
|
||||
class IncrementingNumberGenerator implements NumberGeneratorInterface
|
||||
{
|
||||
private $counter = 0;
|
||||
|
||||
/**
|
||||
* @param InvoiceModel $model
|
||||
*/
|
||||
public function setModel(InvoiceModel $model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInvoiceNumber(): string
|
||||
{
|
||||
return $this->counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique ID of this number generator.
|
||||
*
|
||||
* Prefix it with your company name followed by a hyphen (e.g. "acme-"),
|
||||
* if this is a third-party generator.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'testing';
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class CsvRendererTest extends TestCase
|
||||
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('text/csv', $response->headers->get('Content-Type'));
|
||||
$filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.csv';
|
||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name.csv';
|
||||
$this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition'));
|
||||
|
||||
$this->assertTrue(file_exists($file->getRealPath()));
|
||||
|
||||
@@ -119,6 +119,10 @@ class DebugRendererTest extends TestCase
|
||||
'customer.number',
|
||||
'customer.homepage',
|
||||
'customer.comment',
|
||||
'customer.email',
|
||||
'customer.fax',
|
||||
'customer.phone',
|
||||
'customer.mobile',
|
||||
'customer.meta.foo-customer',
|
||||
'activity.id',
|
||||
'activity.name',
|
||||
|
||||
@@ -45,7 +45,7 @@ class DocxRendererTest extends TestCase
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.docx';
|
||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name.docx';
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition'));
|
||||
|
||||
@@ -56,7 +56,7 @@ class OdsRendererTest extends TestCase
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.ods';
|
||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name.ods';
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition'));
|
||||
|
||||
@@ -62,7 +62,7 @@ class TwigRendererTest extends KernelTestCase
|
||||
|
||||
$content = $response->getContent();
|
||||
|
||||
$filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name';
|
||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name';
|
||||
$this->assertStringContainsString('<title>' . $filename . '</title>', $content);
|
||||
$this->assertStringContainsString('<h2 class="page-header">
|
||||
<span contenteditable="true">a very *long* test invoice / template title with [special] character</span>
|
||||
|
||||
@@ -57,7 +57,7 @@ class XlsxRendererTest extends TestCase
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.xlsx';
|
||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name.xlsx';
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition'));
|
||||
|
||||
@@ -9,12 +9,15 @@
|
||||
|
||||
namespace App\Tests\Invoice;
|
||||
|
||||
use App\Entity\Invoice;
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
||||
use App\Invoice\Renderer\TwigRenderer;
|
||||
use App\Invoice\ServiceInvoice;
|
||||
use App\Repository\InvoiceDocumentRepository;
|
||||
use App\Repository\InvoiceRepository;
|
||||
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
|
||||
use App\Utils\FileHelper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
@@ -27,8 +30,18 @@ class ServiceInvoiceTest extends TestCase
|
||||
private function getSut(array $paths): ServiceInvoice
|
||||
{
|
||||
$repo = new InvoiceDocumentRepository($paths);
|
||||
$invoiceRepo = $this->createMock(InvoiceRepository::class);
|
||||
$userDateTime = (new UserDateTimeFactoryFactory($this))->create();
|
||||
|
||||
return new ServiceInvoice($repo, new FileHelper(realpath(__DIR__ . '/../../var/data/')));
|
||||
return new ServiceInvoice($repo, new FileHelper(realpath(__DIR__ . '/../../var/data/')), $invoiceRepo, $userDateTime, new DebugFormatter());
|
||||
}
|
||||
|
||||
public function testInvalidExceptionOnChangeState()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Unknown invoice status');
|
||||
$sut = $this->getSut([]);
|
||||
$sut->changeInvoiceStatus(new Invoice(), 'foo');
|
||||
}
|
||||
|
||||
public function testEmptyObject()
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<div class="col-sm-5">
|
||||
<p contenteditable="true">
|
||||
<strong>{{ 'invoice.number'|trans({}, 'messages', language) }}:</strong>
|
||||
{{ model.numberGenerator.invoiceNumber }}
|
||||
{{ model.invoiceNumber }}
|
||||
|
||||
<br>
|
||||
<strong>{{ 'invoice.due_days'|trans({}, 'messages', language) }}:</strong>
|
||||
|
||||
Reference in New Issue
Block a user