code cleanup (#3338)
This commit is contained in:
@@ -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>' . $question . '</question>', $default);
|
||||
$question = new ConfirmationQuestion('<question>' . $question . '</question>', false);
|
||||
|
||||
return $questionHelper->ask($input, $output, $question);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user