Release 2.36.1 (#5540)

* fix weekly hours for new entries with non-global activities
* bump packages
* prevent creating invoices with 0 entries
This commit is contained in:
Kevin Papst
2025-06-16 17:53:27 +02:00
committed by GitHub
parent da10099248
commit 59dc82351e
5 changed files with 136 additions and 91 deletions

View File

@@ -158,20 +158,21 @@ class InvoiceCreateCommandTest extends KernelTestCase
public function testCreateWithInvalidCustomer(): void
{
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 3, '--template' => 'x'], 'Unknown customer ID: 3');
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => PHP_INT_MAX, '--template' => 'x'], 'Unknown customer ID: ' . PHP_INT_MAX);
}
public function testCreateWithInvalidProject(): void
{
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--project' => 3, '--template' => 'x'], 'Unknown project ID: 3');
$this->assertCommandErrors(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--project' => PHP_INT_MAX, '--template' => 'x'], 'Unknown project ID: ' . PHP_INT_MAX);
}
public function testCreateInvoice(): void
{
$fixture = new InvoiceTemplateFixtures();
$this->importFixture($fixture);
$start = new \DateTime('2020-01-01');
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => 1, '--template' => 'Invoice', '--start' => '2020-01-01', '--end' => '2020-03-01']);
$customer = $this->prepareFixtures($start)[0];
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => $customer->getId(), '--template' => 'Invoice', '--start' => '2020-01-01', '--end' => '2020-03-01']);
$output = $commandTester->getDisplay();
self::assertStringContainsString('Created 1 invoice(s)', $output);
@@ -179,15 +180,13 @@ class InvoiceCreateCommandTest extends KernelTestCase
self::assertStringContainsString('| Customer', $output);
self::assertStringContainsString('| Total', $output);
self::assertStringContainsString('| Filename', $output);
self::assertStringContainsString('0 EUR', $output);
self::assertStringContainsString('/tests/_data/invoices/' . ((new \DateTime())->format('Y')) . '-001-Test.html |', $output);
self::assertStringContainsString('/tests/_data/invoices/' . ((new \DateTime())->format('Y')) . '-001', $output);
}
/**
* @param \DateTime $start
* @return array<Customer>
* @return array{0: Customer, 1: Project}
*/
protected function prepareFixtures(\DateTime $start): array
protected function prepareFixtures(\DateTime $start, bool $withTimesheets = true): array
{
$fixture = new InvoiceTemplateFixtures();
$invoiceTemplate = $this->importFixture($fixture);
@@ -204,14 +203,16 @@ class InvoiceCreateCommandTest extends KernelTestCase
$fixture->setAmount(1);
$projects = $this->importFixture($fixture);
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByName(UserFixtures::USERNAME_SUPER_ADMIN));
$fixture->setAmount(20);
$fixture->setStartDate($start);
$fixture->setProjects($projects);
$this->importFixture($fixture);
if ($withTimesheets) {
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByName(UserFixtures::USERNAME_SUPER_ADMIN));
$fixture->setAmount(20);
$fixture->setStartDate($start);
$fixture->setProjects($projects);
$this->importFixture($fixture);
}
return [$customer];
return [$customer, $projects[0]];
}
public function testCreateInvoiceByCustomer(): void
@@ -232,15 +233,27 @@ class InvoiceCreateCommandTest extends KernelTestCase
$start = new \DateTime('-2 months');
$end = new \DateTime();
$imports = $this->prepareFixtures($start);
$customer = $imports[0]->getId();
$customer = $this->prepareFixtures($start)[0];
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => $customer . ',1', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => $customer->getId(), '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
$output = $commandTester->getDisplay();
self::assertStringContainsString('Created 1 invoice(s) ', $output);
}
public function testCreateInvoiceByCustomerIdWithoutTimesheets(): void
{
$start = new \DateTime('-2 months');
$end = new \DateTime();
$customer = $this->prepareFixtures($start, false)[0];
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--customer' => $customer->getId(), '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
$output = $commandTester->getDisplay();
self::assertStringContainsString('No invoice was generated', $output);
}
public function testCreateInvoiceByProject(): void
{
$start = new \DateTime('-2 months');
@@ -259,14 +272,27 @@ class InvoiceCreateCommandTest extends KernelTestCase
$start = new \DateTime('-2 months');
$end = new \DateTime();
$this->prepareFixtures($start);
$project = $this->prepareFixtures($start)[1];
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--project' => '1', '--template' => 'Invoice', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--project' => $project->getId(), '--template' => 'Invoice', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
$output = $commandTester->getDisplay();
self::assertStringContainsString('Created 1 invoice(s) ', $output);
}
public function testCreateInvoiceByProjectIdWithoutTimesheets(): void
{
$start = new \DateTime('-2 months');
$end = new \DateTime();
$project = $this->prepareFixtures($start, false)[1];
$commandTester = $this->createInvoice(['--user' => UserFixtures::USERNAME_SUPER_ADMIN, '--exported' => 'all', '--project' => $project->getId(), '--template' => 'Invoice', '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]);
$output = $commandTester->getDisplay();
self::assertStringContainsString('No invoice was generated', $output);
}
public function testCreateInvoiceByProjectWithPreview(): void
{
$start = new \DateTime('-2 months');