code cleanup (#3338)
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
@@ -26,26 +26,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractResetCommand extends Command
|
abstract class AbstractResetCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
protected function configure(): void
|
||||||
* @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()
|
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('kimai:reset:' . $this->getEnvName())
|
->setName('kimai:reset:' . $this->getEnvName())
|
||||||
@@ -61,23 +42,21 @@ EOT
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isEnabled(): bool
|
||||||
* 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()
|
|
||||||
{
|
{
|
||||||
return $this->environment !== 'prod';
|
return $this->getEnv() !== 'prod';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function getEnv(): string
|
||||||
* @param InputInterface $input
|
{
|
||||||
* @param OutputInterface $output
|
/** @var Application $application */
|
||||||
* @return int|null
|
$application = $this->getApplication();
|
||||||
*/
|
$kernel = $application->getKernel();
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
|
||||||
|
return $kernel->getEnvironment();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
@@ -155,14 +134,7 @@ EOT
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function askConfirmation(InputInterface $input, OutputInterface $output, string $question): bool
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @param string $question
|
|
||||||
* @param bool $default
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = false)
|
|
||||||
{
|
{
|
||||||
if (!$input->isInteractive()) {
|
if (!$input->isInteractive()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -170,7 +142,7 @@ EOT
|
|||||||
|
|
||||||
/** @var QuestionHelper $questionHelper */
|
/** @var QuestionHelper $questionHelper */
|
||||||
$questionHelper = $this->getHelperSet()->get('question');
|
$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);
|
return $questionHelper->ask($input, $output, $question);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use App\Entity\Project;
|
|||||||
use App\Entity\Team;
|
use App\Entity\Team;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\UserPreference;
|
use App\Entity\UserPreference;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@@ -27,6 +28,14 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
*/
|
*/
|
||||||
class ResetTestCommand extends AbstractResetCommand
|
class ResetTestCommand extends AbstractResetCommand
|
||||||
{
|
{
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $entityManager)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getEnvName(): string
|
protected function getEnvName(): string
|
||||||
{
|
{
|
||||||
return 'test';
|
return 'test';
|
||||||
|
|||||||
@@ -355,7 +355,12 @@ final class ServiceInvoice
|
|||||||
|
|
||||||
foreach ($this->getRenderer() as $renderer) {
|
foreach ($this->getRenderer() as $renderer) {
|
||||||
if ($renderer->supports($document)) {
|
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())) {
|
if ($this->invoiceRepository->hasInvoice($model->getInvoiceNumber())) {
|
||||||
throw new DuplicateInvoiceNumberException($model->getInvoiceNumber());
|
throw new DuplicateInvoiceNumberException($model->getInvoiceNumber());
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
namespace App\Tests\Command;
|
namespace App\Tests\Command;
|
||||||
|
|
||||||
use App\Command\ResetDevelopmentCommand;
|
use App\Command\ResetDevelopmentCommand;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
@@ -24,15 +23,19 @@ class ResetDevelopmentCommandTest extends KernelTestCase
|
|||||||
{
|
{
|
||||||
$kernel = self::bootKernel();
|
$kernel = self::bootKernel();
|
||||||
$application = new Application($kernel);
|
$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');
|
$command = $application->find('kimai:reset-dev');
|
||||||
self::assertInstanceOf(ResetDevelopmentCommand::class, $command);
|
self::assertInstanceOf(ResetDevelopmentCommand::class, $command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCommandNameIsNotEnabledInProd()
|
public function testCommandNameIsNotEnabledInProd()
|
||||||
{
|
{
|
||||||
$command = new ResetDevelopmentCommand('prod', $this->createMock(EntityManagerInterface::class));
|
$kernel = self::bootKernel(['environment' => 'prod']);
|
||||||
self::assertFalse($command->isEnabled());
|
$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();
|
$kernel = self::bootKernel();
|
||||||
$application = new Application($kernel);
|
$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');
|
$command = $application->find('kimai:reset-test');
|
||||||
self::assertInstanceOf(ResetTestCommand::class, $command);
|
self::assertInstanceOf(ResetTestCommand::class, $command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCommandNameIsNotEnabledInProd()
|
public function testCommandNameIsNotEnabledInProd()
|
||||||
{
|
{
|
||||||
$command = new ResetTestCommand('prod', $this->createMock(EntityManagerInterface::class));
|
$kernel = self::bootKernel(['environment' => 'prod']);
|
||||||
self::assertFalse($command->isEnabled());
|
$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