diff --git a/src/Command/AbstractResetCommand.php b/src/Command/AbstractResetCommand.php
index 23a285cd..09464e96 100644
--- a/src/Command/AbstractResetCommand.php
+++ b/src/Command/AbstractResetCommand.php
@@ -9,8 +9,8 @@
namespace App\Command;
-use Doctrine\ORM\EntityManagerInterface;
use Exception;
+use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
@@ -26,26 +26,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
abstract class AbstractResetCommand extends Command
{
- /**
- * @var string
- */
- private $environment;
- /**
- * @var EntityManagerInterface
- */
- protected $entityManager;
-
- public function __construct(string $kernelEnvironment, EntityManagerInterface $entityManager)
- {
- $this->environment = $kernelEnvironment;
- $this->entityManager = $entityManager;
- parent::__construct();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function configure()
+ protected function configure(): void
{
$this
->setName('kimai:reset:' . $this->getEnvName())
@@ -61,23 +42,21 @@ EOT
;
}
- /**
- * Make sure that this command CANNOT be executed in production.
- * It can't work, as the fixtures bundle is not available in production.
- *
- * @return bool
- */
- public function isEnabled()
+ public function isEnabled(): bool
{
- return $this->environment !== 'prod';
+ return $this->getEnv() !== 'prod';
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int|null
- */
- protected function execute(InputInterface $input, OutputInterface $output)
+ private function getEnv(): string
+ {
+ /** @var Application $application */
+ $application = $this->getApplication();
+ $kernel = $application->getKernel();
+
+ return $kernel->getEnvironment();
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
@@ -155,14 +134,7 @@ EOT
return 0;
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @param string $question
- * @param bool $default
- * @return bool
- */
- private function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = false)
+ private function askConfirmation(InputInterface $input, OutputInterface $output, string $question): bool
{
if (!$input->isInteractive()) {
return true;
@@ -170,7 +142,7 @@ EOT
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getHelperSet()->get('question');
- $question = new ConfirmationQuestion('' . $question . '', $default);
+ $question = new ConfirmationQuestion('' . $question . '', false);
return $questionHelper->ask($input, $output, $question);
}
diff --git a/src/Command/ResetTestCommand.php b/src/Command/ResetTestCommand.php
index 1c5bde47..e440443c 100644
--- a/src/Command/ResetTestCommand.php
+++ b/src/Command/ResetTestCommand.php
@@ -15,6 +15,7 @@ use App\Entity\Project;
use App\Entity\Team;
use App\Entity\User;
use App\Entity\UserPreference;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -27,6 +28,14 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class ResetTestCommand extends AbstractResetCommand
{
+ private $entityManager;
+
+ public function __construct(EntityManagerInterface $entityManager)
+ {
+ parent::__construct();
+ $this->entityManager = $entityManager;
+ }
+
protected function getEnvName(): string
{
return 'test';
diff --git a/src/Invoice/ServiceInvoice.php b/src/Invoice/ServiceInvoice.php
index a38af9ac..09f6e064 100644
--- a/src/Invoice/ServiceInvoice.php
+++ b/src/Invoice/ServiceInvoice.php
@@ -355,7 +355,12 @@ final class ServiceInvoice
foreach ($this->getRenderer() as $renderer) {
if ($renderer->supports($document)) {
- $dispatcher->dispatch(new InvoicePreRenderEvent($model, $document, $renderer));
+ $preEvent = new InvoicePreRenderEvent($model, $document, $renderer);
+ $dispatcher->dispatch($preEvent);
+
+ if ($preEvent->isPropagationStopped()) {
+ continue;
+ }
if ($this->invoiceRepository->hasInvoice($model->getInvoiceNumber())) {
throw new DuplicateInvoiceNumberException($model->getInvoiceNumber());
diff --git a/tests/Command/ResetDevelopmentCommandTest.php b/tests/Command/ResetDevelopmentCommandTest.php
index f9750fa0..d4538535 100644
--- a/tests/Command/ResetDevelopmentCommandTest.php
+++ b/tests/Command/ResetDevelopmentCommandTest.php
@@ -10,7 +10,6 @@
namespace App\Tests\Command;
use App\Command\ResetDevelopmentCommand;
-use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -24,15 +23,19 @@ class ResetDevelopmentCommandTest extends KernelTestCase
{
$kernel = self::bootKernel();
$application = new Application($kernel);
- $application->add(new ResetDevelopmentCommand('test', $this->createMock(EntityManagerInterface::class)));
+ $application->add(new ResetDevelopmentCommand());
+ self::assertTrue($application->has('kimai:reset-dev'));
$command = $application->find('kimai:reset-dev');
self::assertInstanceOf(ResetDevelopmentCommand::class, $command);
}
public function testCommandNameIsNotEnabledInProd()
{
- $command = new ResetDevelopmentCommand('prod', $this->createMock(EntityManagerInterface::class));
- self::assertFalse($command->isEnabled());
+ $kernel = self::bootKernel(['environment' => 'prod']);
+ $application = new Application($kernel);
+ $application->add(new ResetDevelopmentCommand());
+
+ self::assertFalse($application->has('kimai:reset-dev'));
}
}
diff --git a/tests/Command/ResetTestCommandTest.php b/tests/Command/ResetTestCommandTest.php
index 366e85fe..39d560b7 100644
--- a/tests/Command/ResetTestCommandTest.php
+++ b/tests/Command/ResetTestCommandTest.php
@@ -24,15 +24,19 @@ class ResetTestCommandTest extends KernelTestCase
{
$kernel = self::bootKernel();
$application = new Application($kernel);
- $application->add(new ResetTestCommand('test', $this->createMock(EntityManagerInterface::class)));
+ $application->add(new ResetTestCommand($this->createMock(EntityManagerInterface::class)));
+ self::assertTrue($application->has('kimai:reset-test'));
$command = $application->find('kimai:reset-test');
self::assertInstanceOf(ResetTestCommand::class, $command);
}
public function testCommandNameIsNotEnabledInProd()
{
- $command = new ResetTestCommand('prod', $this->createMock(EntityManagerInterface::class));
- self::assertFalse($command->isEnabled());
+ $kernel = self::bootKernel(['environment' => 'prod']);
+ $application = new Application($kernel);
+ $application->add(new ResetTestCommand($this->createMock(EntityManagerInterface::class)));
+
+ self::assertFalse($application->has('kimai:reset-test'));
}
}