From fd4cbb43c17ced6eafab9e63fe23c067671bc438 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Thu, 20 Jan 2022 17:10:56 +0100 Subject: [PATCH] bugfixes (#3078) * fix phpdoc * fix invoice export field order * prevent empty migration warning * do not trigger export validation on new timesheets * update license year * remove trailing comma in function call for php compatibility * add new composer plugin config * bump phpunit schema version --- LICENSE | 2 +- composer.json | 6 +++++- phpunit.xml.dist | 12 ++++-------- src/Command/TranslationCommand.php | 2 +- src/Entity/Activity.php | 2 +- src/Entity/Customer.php | 2 +- src/Entity/Invoice.php | 2 +- src/Migrations/Version20211008092010.php | 2 ++ .../TimesheetExportedValidator.php | 4 ++++ .../TimesheetExportedValidatorTest.php | 19 +++++++++++++++++-- 10 files changed, 37 insertions(+), 16 deletions(-) diff --git a/LICENSE b/LICENSE index 312dbe21..35f38be3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2019 Kevin Papst @ https://www.kevinpapst.de +Copyright (c) 2017-2022 Kevin Papst @ https://www.kevinpapst.de Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 955ea923..0acd1671 100644 --- a/composer.json +++ b/composer.json @@ -107,7 +107,11 @@ "preferred-install": { "*": "dist" }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "composer/package-versions-deprecated": true, + "symfony/flex": true + } }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8da5d755..eb29f5b3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,9 @@ - - + bootstrap="tests/bootstrap.php"> @@ -64,9 +61,8 @@ diff --git a/src/Command/TranslationCommand.php b/src/Command/TranslationCommand.php index e54384cb..c031b3cf 100644 --- a/src/Command/TranslationCommand.php +++ b/src/Command/TranslationCommand.php @@ -286,7 +286,7 @@ class TranslationCommand extends Command $id, $values['resname'], $values['source'], - $values['target'], + $values['target'] ); } diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index 4b4c9f9e..da0aed84 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -325,7 +325,7 @@ class Activity implements EntityWithMetaFields, EntityWithBudget $currentMeta = $this->meta; $this->meta = new ArrayCollection(); - /** @var ProjectMeta $meta */ + /** @var ActivityMeta $meta */ foreach ($currentMeta as $meta) { $newMeta = clone $meta; $newMeta->setEntity($this); diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index aae34c19..2dae7328 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -595,7 +595,7 @@ class Customer implements EntityWithMetaFields, EntityWithBudget $currentMeta = $this->meta; $this->meta = new ArrayCollection(); - /** @var ProjectMeta $meta */ + /** @var CustomerMeta $meta */ foreach ($currentMeta as $meta) { $newMeta = clone $meta; $newMeta->setEntity($this); diff --git a/src/Entity/Invoice.php b/src/Entity/Invoice.php index f63ce0df..3e8dd6b5 100644 --- a/src/Entity/Invoice.php +++ b/src/Entity/Invoice.php @@ -29,7 +29,7 @@ use Symfony\Component\Validator\Constraints as Assert; * @UniqueEntity("invoiceNumber") * @UniqueEntity("invoiceFilename") * - * @Exporter\Order({"id", "createdAt", "invoiceNumber", "status", "customer", "subtotal", "total", "tax", "currency", "vat", "dueDays", "dueDate", "paymentDate", "user", "invoiceFilename", "comment"}) + * @Exporter\Order({"id", "createdAt", "invoiceNumber", "status", "customer", "subtotal", "total", "tax", "currency", "vat", "dueDays", "dueDate", "paymentDate", "user", "invoiceFilename", "customerNumber", "comment"}) * @Exporter\Expose("customer", label="label.customer", exp="object.getCustomer() === null ? null : object.getCustomer().getName()") * @Exporter\Expose("customerNumber", label="label.number", exp="object.getCustomer() === null ? null : object.getCustomer().getNumber()") * @Exporter\Expose("dueDate", label="invoice.due_days", type="datetime", exp="object.getDueDate() === null ? null : object.getDueDate()") diff --git a/src/Migrations/Version20211008092010.php b/src/Migrations/Version20211008092010.php index 218fa86b..6256ab57 100644 --- a/src/Migrations/Version20211008092010.php +++ b/src/Migrations/Version20211008092010.php @@ -38,5 +38,7 @@ final class Version20211008092010 extends AbstractMigration $projects = $schema->getTable('kimai2_projects'); $column = $projects->getColumn('order_number'); $column->setOptions(['length' => 20]); + + $this->preventEmptyMigrationWarning(); } } diff --git a/src/Validator/Constraints/TimesheetExportedValidator.php b/src/Validator/Constraints/TimesheetExportedValidator.php index 4e90f911..a016ab44 100644 --- a/src/Validator/Constraints/TimesheetExportedValidator.php +++ b/src/Validator/Constraints/TimesheetExportedValidator.php @@ -38,6 +38,10 @@ final class TimesheetExportedValidator extends ConstraintValidator throw new UnexpectedTypeException($timesheet, TimesheetEntity::class); } + if ($timesheet->getId() === null) { + return; + } + if (!$timesheet->isExported()) { return; } diff --git a/tests/Validator/Constraints/TimesheetExportedValidatorTest.php b/tests/Validator/Constraints/TimesheetExportedValidatorTest.php index 8b6a33ad..14e2ded2 100644 --- a/tests/Validator/Constraints/TimesheetExportedValidatorTest.php +++ b/tests/Validator/Constraints/TimesheetExportedValidatorTest.php @@ -66,8 +66,9 @@ class TimesheetExportedValidatorTest extends ConstraintValidatorTestCase $this->validator = $this->createMyValidator(false); $this->validator->initialize($this->context); - $timesheet = new Timesheet(); - $timesheet->setExported(true); + $timesheet = $this->createMock(Timesheet::class); + $timesheet->method('isExported')->willReturn(true); + $timesheet->method('getId')->willReturn(1); $this->validator->validate($timesheet, new TimesheetExported()); @@ -77,6 +78,20 @@ class TimesheetExportedValidatorTest extends ConstraintValidatorTestCase ->assertRaised(); } + public function testNotTriggersOnNewTimesheet() + { + $this->validator = $this->createMyValidator(false); + $this->validator->initialize($this->context); + + $timesheet = $this->createMock(Timesheet::class); + $timesheet->method('isExported')->willReturn(true); + $timesheet->method('getId')->willReturn(null); + + $this->validator->validate($timesheet, new TimesheetExported()); + + $this->assertNoViolation(); + } + public function testDoesNotTriggerWithPermission() { $this->validator = $this->createMyValidator(true);