Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -12,7 +12,6 @@ namespace App\Tests\Command;
|
||||
use App\Command\InvoiceCreateCommand;
|
||||
use App\DataFixtures\UserFixtures;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerMeta;
|
||||
use App\Entity\Project;
|
||||
use App\Invoice\ServiceInvoice;
|
||||
use App\Repository\CustomerRepository;
|
||||
@@ -36,12 +35,9 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
{
|
||||
use KernelTestTrait;
|
||||
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
protected Application $application;
|
||||
|
||||
private function clearInvoiceFiles()
|
||||
private function clearInvoiceFiles(): void
|
||||
{
|
||||
$path = __DIR__ . '/../_data/invoices/';
|
||||
|
||||
@@ -65,7 +61,7 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
$this->clearInvoiceFiles();
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
$container = self::$container;
|
||||
$container = self::getContainer();
|
||||
|
||||
$this->application->add(new InvoiceCreateCommand(
|
||||
$container->get(ServiceInvoice::class),
|
||||
@@ -94,7 +90,7 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
* @param array $options
|
||||
* @return CommandTester
|
||||
*/
|
||||
protected function createInvoice(array $options = [])
|
||||
protected function createInvoice(array $options = []): CommandTester
|
||||
{
|
||||
$command = $this->application->find('kimai:invoice:create');
|
||||
$commandTester = new CommandTester($command);
|
||||
@@ -105,7 +101,7 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
return $commandTester;
|
||||
}
|
||||
|
||||
protected function assertCommandErrors(array $options = [], string $errorMessage = '')
|
||||
protected function assertCommandErrors(array $options = [], string $errorMessage = ''): void
|
||||
{
|
||||
$commandTester = $this->createInvoice($options);
|
||||
|
||||
@@ -113,67 +109,62 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
$this->assertStringContainsString('[ERROR] ' . $errorMessage, $output);
|
||||
}
|
||||
|
||||
public function testCreateWithUnknownExportFilter()
|
||||
public function testCreateWithUnknownExportFilter(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'foo'], 'Unknown "exported" filter given');
|
||||
}
|
||||
|
||||
public function testCreateWithMissingUser()
|
||||
public function testCreateWithMissingUser(): void
|
||||
{
|
||||
$this->assertCommandErrors([], 'You must set a "user" to create invoices');
|
||||
}
|
||||
|
||||
public function testCreateWithInvalidUser()
|
||||
public function testCreateWithInvalidUser(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => 'assdfd'], 'The given username "assdfd" could not be resolved');
|
||||
}
|
||||
|
||||
public function testCreateWithMissingEnd()
|
||||
public function testCreateWithMissingEnd(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--start' => '2020-01-01'], 'You need to supply a end date if a start date was given');
|
||||
}
|
||||
|
||||
public function testCreateByCustomerAndByProject()
|
||||
public function testCreateByCustomerAndByProject(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--by-customer' => null, '--by-project' => null], 'You cannot mix "by-customer" and "by-project"');
|
||||
}
|
||||
|
||||
public function testCreateWithMissingGenerationMode()
|
||||
public function testCreateWithMissingGenerationMode(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN], 'Could not determine generation mode');
|
||||
}
|
||||
|
||||
public function testCreateWithMissingTemplate()
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 1], 'You must either pass the "template" or "template-meta" option');
|
||||
}
|
||||
|
||||
public function testCreateWithInvalidStart()
|
||||
public function testCreateWithInvalidStart(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 1, '--exported' => 'exported', '--template' => 'x', '--start' => 'öäüß', '--end' => '2020-01-01'], 'Invalid start date given');
|
||||
}
|
||||
|
||||
public function testCreateWithInvalidEnd()
|
||||
public function testCreateWithInvalidEnd(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 1, '--template' => 'x', '--start' => '2020-01-01', '--end' => 'öäüß'], 'Invalid end date given');
|
||||
}
|
||||
|
||||
public function testCreateWithInvalidPreviewDirectory()
|
||||
public function testCreateWithInvalidPreviewDirectory(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 1, '--template' => 'x', '--start' => '2020-01-01', '--end' => '2020-01-02', '--preview' => '/kjhg/'], 'Invalid preview directory given');
|
||||
}
|
||||
|
||||
public function testCreateWithInvalidCustomer()
|
||||
public function testCreateWithInvalidCustomer(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 3, '--template' => 'x'], 'Unknown customer ID: 3');
|
||||
}
|
||||
|
||||
public function testCreateWithInvalidProject()
|
||||
public function testCreateWithInvalidProject(): void
|
||||
{
|
||||
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--project' => 3, '--template' => 'x'], 'Unknown project ID: 3');
|
||||
}
|
||||
|
||||
public function testCreateInvoice()
|
||||
public function testCreateInvoice(): void
|
||||
{
|
||||
$fixture = new InvoiceTemplateFixtures();
|
||||
$this->importFixture($fixture);
|
||||
@@ -190,15 +181,19 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
$this->assertStringContainsString('/tests/_data/invoices/' . ((new \DateTime())->format('Y')) . '-001-Test.html |', $output);
|
||||
}
|
||||
|
||||
protected function prepareFixtures(\DateTime $start)
|
||||
/**
|
||||
* @param \DateTime $start
|
||||
* @return array<Customer>
|
||||
*/
|
||||
protected function prepareFixtures(\DateTime $start): array
|
||||
{
|
||||
$fixture = new InvoiceTemplateFixtures();
|
||||
$invoiceTemplate = $this->importFixture($fixture);
|
||||
|
||||
$fixture = new CustomerFixtures();
|
||||
$fixture->setAmount(1);
|
||||
$fixture->setCallback(function (Customer $customer) {
|
||||
$meta = new CustomerMeta();
|
||||
$meta->setName('template');
|
||||
$meta->setValue('Invoice');
|
||||
$customer->setMetaField($meta);
|
||||
$fixture->setCallback(function (Customer $customer) use ($invoiceTemplate) {
|
||||
$customer->setInvoiceTemplate($invoiceTemplate[0]);
|
||||
});
|
||||
$customer = $this->importFixture($fixture)[0];
|
||||
|
||||
@@ -214,26 +209,23 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
$fixture->setProjects($projects);
|
||||
$this->importFixture($fixture);
|
||||
|
||||
$fixture = new InvoiceTemplateFixtures();
|
||||
$this->importFixture($fixture);
|
||||
|
||||
return [$customer];
|
||||
}
|
||||
|
||||
public function testCreateInvoiceByCustomer()
|
||||
public function testCreateInvoiceByCustomer(): void
|
||||
{
|
||||
$start = new \DateTime('-2 months');
|
||||
$end = new \DateTime();
|
||||
|
||||
$this->prepareFixtures($start);
|
||||
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--by-customer' => null, '--template-meta' => 'template', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--by-customer' => null, '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Created 1 invoice(s) ', $output);
|
||||
}
|
||||
|
||||
public function testCreateInvoiceByCustomerId()
|
||||
public function testCreateInvoiceByCustomerId(): void
|
||||
{
|
||||
$start = new \DateTime('-2 months');
|
||||
$end = new \DateTime();
|
||||
@@ -241,26 +233,26 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
$imports = $this->prepareFixtures($start);
|
||||
$customer = $imports[0]->getId();
|
||||
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => $customer . ',1', '--template-meta' => 'template', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => $customer . ',1', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Created 1 invoice(s) ', $output);
|
||||
}
|
||||
|
||||
public function testCreateInvoiceByProject()
|
||||
public function testCreateInvoiceByProject(): void
|
||||
{
|
||||
$start = new \DateTime('-2 months');
|
||||
$end = new \DateTime();
|
||||
|
||||
$this->prepareFixtures($start);
|
||||
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--by-project' => null, '--template-meta' => 'template', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--by-project' => null, '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Created 1 invoice(s) ', $output);
|
||||
}
|
||||
|
||||
public function testCreateInvoiceByProjectId()
|
||||
public function testCreateInvoiceByProjectId(): void
|
||||
{
|
||||
$start = new \DateTime('-2 months');
|
||||
$end = new \DateTime();
|
||||
@@ -273,14 +265,14 @@ class InvoiceCreateCommandTest extends KernelTestCase
|
||||
$this->assertStringContainsString('Created 1 invoice(s) ', $output);
|
||||
}
|
||||
|
||||
public function testCreateInvoiceByProjectWithPreview()
|
||||
public function testCreateInvoiceByProjectWithPreview(): void
|
||||
{
|
||||
$start = new \DateTime('-2 months');
|
||||
$end = new \DateTime();
|
||||
|
||||
$this->prepareFixtures($start);
|
||||
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--preview' => sys_get_temp_dir(), '--by-project' => null, '--template-meta' => 'template', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--preview' => sys_get_temp_dir(), '--by-project' => null, '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Created 1 invoice(s) ', $output);
|
||||
|
||||
Reference in New Issue
Block a user