diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9547abb..a2c55f8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,10 +3,12 @@ name: cronBundle on: push: branches: - - 1.0-dev + - develop + - main pull_request: branches: - - 1.0-dev + - develop + - main jobs: phpunit: @@ -14,7 +16,7 @@ jobs: steps: - uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28 with: - php-version: '8.2' + php-version: '8.3' - uses: samin/mysql-action@v1.3 with: mysql root password: root @@ -24,4 +26,6 @@ jobs: - name: Check Code Styles run: vendor/bin/ecs - name: Execute tests (Unit and Feature tests) via PHPUnit - run: vendor/bin/simple-phpunit \ No newline at end of file + run: vendor/bin/simple-phpunit + - name: Check with phpstan + run: vendor/bin/phpstan analyse \ No newline at end of file diff --git a/Makefile b/Makefile index 4a13135..31a4daa 100644 --- a/Makefile +++ b/Makefile @@ -31,4 +31,8 @@ ecs: ## PHP Unit phpunit: - vendor/bin/simple-phpunit + vendor/bin/simple-phpunit -v + +## PHP Stan +phpstan: + vendor/bin/phpstan analyse diff --git a/composer.json b/composer.json index c39a19a..9c3ae6e 100644 --- a/composer.json +++ b/composer.json @@ -12,17 +12,21 @@ { "name": "Felix Ammann", "email": "fexu@whatwedo.ch" + }, + { + "name": "whatwedo GmbH", + "email": "welove@whatwedo.ch" } ], "require": { - "php": ">=8.1", + "php": ">=8.3", "ext-posix": "*", "dragonmantank/cron-expression": "~3.3", - "symfony/console": "^7.0|^6.4|^5.4", - "symfony/event-dispatcher": "^7.0|^6.4|^5.4", - "symfony/security-bundle": "^7.0|^6.4|^5.4", - "symfony/framework-bundle": "^7.0|^6.4|^5.4", - "symfony/process": "^7.0|^6.4|^5.4", + "symfony/console": "^7.1|^6.4", + "symfony/event-dispatcher": "^7.1|^6.4", + "symfony/security-bundle": "^7.1|^6.4", + "symfony/framework-bundle": "^7.1|^6.4", + "symfony/process": "^7.1|^6.4", "symfony/webpack-encore-bundle": "^1.14|^2.1", "symfony/stimulus-bundle": "^2.16" }, @@ -30,25 +34,26 @@ "doctrine/doctrine-bundle": "^2.5", "doctrine/orm": "^2.11|3.0", "doctrine/annotations": "^1.13.2|^2.0", - "symfony/phpunit-bridge": "^7.0", - "symfony/http-kernel": "^7.0", - "symfony/config": "^7.0", - "symfony/dependency-injection": "^7.0", - "symfony/yaml": "^7.0", - "symfony/validator": "^7.0", + "symfony/phpunit-bridge": "^7.1", + "symfony/http-kernel": "^7.1", + "symfony/config": "^7.1", + "symfony/dependency-injection": "^7.1", + "symfony/yaml": "^7.1", + "symfony/validator": "^7.1", "symfony/maker-bundle": "^1.0.0", "symfony/orm-pack": "^2.4", - "symfony/translation": "^7.0", - "symfony/twig-bundle": "^7.0", + "symfony/translation": "^7.1", + "symfony/twig-bundle": "^7.1", "symfony/test-pack": "^1.0", - "symfony/runtime": "^7.0", - "symfony/dotenv": "^7.0", + "symfony/runtime": "^7.1", + "symfony/dotenv": "^7.1", "gedmo/doctrine-extensions": "^3.5", - "whatwedo/php-coding-standard": "dev-develop", + "whatwedo/php-coding-standard": "^1.2", "whatwedo/twig-bootstrap-icons": "^1.0", - "zenstruck/foundry": "^1.21", + "zenstruck/foundry": "^2.1", "zenstruck/console-test": "^v1.3.0", - "zenstruck/browser": "^1.2" + "zenstruck/browser": "^1.2", + "phpstan/phpstan": "^1.12" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php index c5d54aa..76690b2 100644 --- a/ecs.php +++ b/ecs.php @@ -5,7 +5,6 @@ use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\ClassCommentSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\FileCommentSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\FunctionCommentThrowTagSniff; -use Symplify\EasyCodingStandard\ValueObject\Option; use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { @@ -13,10 +12,8 @@ __DIR__ . '/src', __DIR__ . '/tests', ]); - $ecsConfig->import('vendor/whatwedo/php-coding-standard/config/whatwedo-symfony.php'); - - $ecsConfig->parameters()->set(Option::SKIP, [ + $ecsConfig->skip([ FileCommentSniff::class, ClassCommentSniff::class, FunctionCommentThrowTagSniff::class, @@ -26,6 +23,5 @@ ], ]); - - $ecsConfig->parameters()->set(Option::PARALLEL, true); + $ecsConfig->parallel(); }; diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..7f33c04 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,5 @@ +parameters: + level: 8 + paths: + - src + - tests diff --git a/src/Command/CleanupCommand.php b/src/Command/CleanupCommand.php index 7e50f52..831f45c 100644 --- a/src/Command/CleanupCommand.php +++ b/src/Command/CleanupCommand.php @@ -50,7 +50,6 @@ protected function configure(): void $this ->addOption('max-retention', null, InputOption::VALUE_REQUIRED, 'The maximum retention time (will be parsed by DateTime).', '1 month') ->addOption('max-retention-successful', null, InputOption::VALUE_REQUIRED, 'The maximum retention time for succeeded jobs (will be parsed by DateTime).', '7 days') - ->addOption('per-call', null, InputOption::VALUE_REQUIRED, 'The maximum number of jobs to clean-up per call.', 1000) ; } @@ -59,11 +58,8 @@ protected function configure(): void */ protected function execute(InputInterface $input, OutputInterface $output): int { - $perCall = (int) $input->getOption('per-call'); - $deletedSuccessful = $this->executionRepository->deleteSuccessfulJobs( - new \DateTimeImmutable('-'.$input->getOption('max-retention-successful')), - $perCall + new \DateTimeImmutable('-'.$input->getOption('max-retention-successful')) ); $output->writeln(sprintf( @@ -72,8 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int )); $deletedNotSuccessful = $this->executionRepository->deleteNotSuccessfulJobs( - new \DateTimeImmutable('-'.$input->getOption('max-retention')), - $perCall + new \DateTimeImmutable('-'.$input->getOption('max-retention')) ); $output->writeln(sprintf( diff --git a/src/Command/ExecuteCommand.php b/src/Command/ExecuteCommand.php index db86772..6934baa 100644 --- a/src/Command/ExecuteCommand.php +++ b/src/Command/ExecuteCommand.php @@ -67,7 +67,7 @@ public function checkMaxRuntime(Execution $execution, CronInterface $cronJob, Pr return; } $now = new \DateTime(); - $diff = $now->getTimestamp() - $execution->getStartedAt()->getTimestamp(); + $diff = $now->getTimestamp() - ($execution->getStartedAt() ?? $now)->getTimestamp(); if ($diff > $cronJob->getMaxRuntime()) { $this->logger->info(sprintf('execute: max RunTime reached PID:%s', $process->getPid())); $execution @@ -75,7 +75,7 @@ public function checkMaxRuntime(Execution $execution, CronInterface $cronJob, Pr ->setPid(null) ->setStdout($process->getOutput()) ->setStderr($process->getErrorOutput()); - $this->entityManager->flush($execution); + $this->entityManager->flush(); throw new MaxRuntimeReachedException($execution); } } @@ -105,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ->setState(Execution::STATE_RUNNING) ->setCommand($command); $this->entityManager->persist($execution); - $this->entityManager->flush($execution); + $this->entityManager->flush(); // Run command $process = new Process($command, $this->projectDir); @@ -113,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $process->start(); $execution->setPid($process->getPid()); $this->logger->info(sprintf('execute %s: PID:%s', $logId, $execution->getPid())); - $this->entityManager->flush($execution); + $this->entityManager->flush(); $this->eventDispatcher->dispatch(new CronStartEvent($cronJob), CronStartEvent::NAME); // Update command output every 5 seconds @@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int sleep(5); $execution->setStdout($process->getOutput()) ->setStderr($process->getErrorOutput()); - $this->entityManager->flush($execution); + $this->entityManager->flush(); } $this->logger->info(sprintf('execute %s: is finisched PID:%s', $logId, $execution->getPid())); @@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Finish execution $output->writeln('Execution finished with exit code '.$process->getExitCode()); - $this->logger->info(sprintf('execute %s: is finisched PID:%s exitCode:', $logId, $execution->getPid(), $process->getExitCode())); + $this->logger->info(sprintf('execute %s: is finished PID: %s exitCode: %s', $logId, $execution->getPid(), $process->getExitCode())); $execution ->setState(Execution::STATE_FINISHED) @@ -151,13 +151,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $execution->setState(Execution::STATE_ERROR); } - $this->entityManager->flush($execution); + $this->entityManager->flush(); $this->eventDispatcher->dispatch(new CronFinishEvent($cronJob), CronFinishEvent::NAME); // cleanup Executions foreach ($cronJob->getExecutionRetention() as $state => $maxRetained) { - $expr = $this->entityManager->getExpressionBuilder(); - $topIds = $this->entityManager->getRepository(Execution::class)->createQueryBuilder('execution') ->select('execution.id') ->where('execution.job = :jobClass') @@ -199,7 +197,7 @@ protected function getCronCommand(CronInterface $cron): string } if ($cron instanceof Command) { - return $cron->getDefaultName(); + return $cron->getDefaultName() ?? ''; } return ''; diff --git a/src/Command/InfoCommand.php b/src/Command/InfoCommand.php index dd949c1..f8a5311 100644 --- a/src/Command/InfoCommand.php +++ b/src/Command/InfoCommand.php @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $table->setHeaders(['Name', 'Value']); $table->addRows([ ['Cron job', get_class($cronJob)], - ['Description', $cronJob->getDescription()], + ['Description', $cronJob instanceof CronJobInterface ? $cronJob->getDescription() : $cronJob::class], ['Expression', $cronJob->getExpression()], ['Command', $this->getCommand($cronJob)], ['Arguments', $this->getArgumentString($cronJob)], @@ -97,7 +97,7 @@ protected function getCommand(CronInterface $cronJob): string } if ($cronJob instanceof Command) { - return $cronJob->getDefaultName(); + return $cronJob->getDefaultName() ?? ''; } return ''; @@ -139,7 +139,7 @@ protected function getNextExecutionDateString(CronInterface $cronJob): ?string return $this->getFormattedDate($nextExecutionDate); } - protected function getFormattedDate(\DateTime $date): ?string + protected function getFormattedDate(?\DateTime $date): ?string { if (! $date) { return null; diff --git a/src/Command/ListCommand.php b/src/Command/ListCommand.php index ad14201..27bfc5e 100644 --- a/src/Command/ListCommand.php +++ b/src/Command/ListCommand.php @@ -35,6 +35,7 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use whatwedo\CronBundle\CronJob\CronJobInterface; use whatwedo\CronBundle\Manager\CronJobManager; #[AsCommand(name: 'whatwedo:cron:list', description: 'List all cron jobs')] @@ -57,7 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $nextRunDate = $cronExpression->getNextRunDate()->format('Y-m-d H:i:s'); } - $table->addRow([get_class($cronJob), $cronJob->getDescription(), $nextRunDate]); + $description = $cronJob instanceof CronJobInterface ? $cronJob->getDescription() : $cronJob::class; + $table->addRow([get_class($cronJob), $description, $nextRunDate]); } $table->render(); diff --git a/src/Controller/CronJobController.php b/src/Controller/CronJobController.php index 9dd0b9a..6410886 100644 --- a/src/Controller/CronJobController.php +++ b/src/Controller/CronJobController.php @@ -8,6 +8,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use whatwedo\CronBundle\Entity\Execution; +use whatwedo\CronBundle\Exception\CronJobNotFoundException; use whatwedo\CronBundle\Manager\CronJobManager; use whatwedo\CronBundle\Manager\ExecutionManager; use whatwedo\CronBundle\Repository\ExecutionRepository; @@ -53,10 +54,9 @@ public function show(string $class): Response } return $this->render('@whatwedoCron/show.html.twig', [ - 'content_title' => $cronJob->getCommand(), + 'content_title' => $cronJob::class, 'cronjob' => $cronJob, 'lastExecutions' => $lastExecutions, - 'activable' => $cronJob instanceof CronJobActivable, 'allwedToRun' => $allowedToRun, 'nextExecutionDate' => $this->executionManager->getNextExecutionDate($cronJob), ]); @@ -102,45 +102,12 @@ public function run(string $class): Response ])); } - public function activate(string $class): Response - { - $cronJob = $this->cronJobManager->getCronJob($class); - if (! $cronJob instanceof CronJobActivable) { - throw new \Exception('Job not deactivable in Frontend'); - } - - $this->addFlash('success', 'cronjob.activate'); - - $url = $this->generateUrl('whatwedo_cronjob_show', [ - 'class' => $class, - ]); - - return $this->redirect($url); - } - - public function deactivate(string $class): Response - { - $cronJob = $this->cronJobManager->getCronJob($class); - - if (! $cronJob instanceof CronJobActivable) { - throw new \Exception('Job not deactivable in Frontend'); - } - - $this->addFlash('success', 'cronjob.deactivate'); - - $url = $this->generateUrl('whatwedo_cronjob_show', [ - 'class' => $class, - ]); - - return $this->redirect($url); - } - public function clean(string $class, string $state): Response { - $cronJob = $this->cronJobManager->getCronJob($class); - - if (! $cronJob) { - throw new \Exception('Job not found'); + try { + $cronJob = $this->cronJobManager->getCronJob($class); + } catch (CronJobNotFoundException) { + throw $this->createNotFoundException(); } $this->executionRepository->deleteExecutions($cronJob, $state); diff --git a/src/CronJob/CleanupCronJob.php b/src/CronJob/CleanupCronJob.php index 2b18e99..70f9eef 100644 --- a/src/CronJob/CleanupCronJob.php +++ b/src/CronJob/CleanupCronJob.php @@ -35,7 +35,7 @@ class CleanupCronJob { public function getCommand(): string { - return CleanupCommand::getDefaultName(); + return CleanupCommand::getDefaultName() ?? throw new \RuntimeException('Command name not found'); } public function getExpression(): string diff --git a/src/CronJob/CronInterface.php b/src/CronJob/CronInterface.php index b5397fb..6a9ff0d 100644 --- a/src/CronJob/CronInterface.php +++ b/src/CronJob/CronInterface.php @@ -54,5 +54,8 @@ public function isParallelAllowed(): bool; */ public function isActive(): bool; + /** + * @return array + */ public function getExecutionRetention(): array; } diff --git a/src/Entity/Execution.php b/src/Entity/Execution.php index 86ca180..5ba314d 100644 --- a/src/Entity/Execution.php +++ b/src/Entity/Execution.php @@ -64,6 +64,9 @@ class Execution #[ORM\Column(type: Types::STRING, length: 255, nullable: false)] protected string $job; + /** + * @var string[]|null + */ #[ORM\Column(type: Types::JSON, nullable: false)] protected ?array $command = []; @@ -106,7 +109,7 @@ public function getState(): ?string return $this->state; } - public function setState(?string $state): self + public function setState(string $state): self { $this->state = $state; @@ -118,7 +121,7 @@ public function getJob(): ?string return $this->job; } - public function setJob(?string $job): self + public function setJob(string $job): self { $this->job = $job; @@ -148,7 +151,7 @@ public function getStartedAt(): ?\DateTime return $this->startedAt; } - public function setStartedAt(?\DateTime $startedAt): self + public function setStartedAt(\DateTime $startedAt): self { $this->startedAt = $startedAt; @@ -160,7 +163,7 @@ public function getUpdatedAt(): ?\DateTime return $this->updatedAt; } - public function setUpdatedAt(?\DateTime $updatedAt): self + public function setUpdatedAt(\DateTime $updatedAt): self { $this->updatedAt = $updatedAt; diff --git a/src/EventListener/ExecutionSubscriber.php b/src/EventListener/ExecutionSubscriber.php index 8f8368c..418196d 100644 --- a/src/EventListener/ExecutionSubscriber.php +++ b/src/EventListener/ExecutionSubscriber.php @@ -30,7 +30,7 @@ namespace whatwedo\CronBundle\EventListener; use Doctrine\Common\EventSubscriber; -use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\ORM\Event\PostLoadEventArgs; use Doctrine\ORM\Events; use Psr\Log\LoggerInterface; use whatwedo\CronBundle\Entity\Execution; @@ -67,7 +67,7 @@ public function getSubscribedEvents(): array ]; } - public function postLoad(LifecycleEventArgs $args): void + public function postLoad(PostLoadEventArgs $args): void { // Only apply on entities which are instance of Execution $entity = $args->getObject(); @@ -77,7 +77,7 @@ public function postLoad(LifecycleEventArgs $args): void // Load cron job try { - $entity->setCronJob($this->cronJobManager->getCronJob($entity->getJob())); + $entity->setCronJob($this->cronJobManager->getCronJob($entity->getJob() ?? '')); } catch (CronJobNotFoundException $ex) { $this->logger->warning($ex->getMessage()); } diff --git a/src/Manager/CronJobManager.php b/src/Manager/CronJobManager.php index f12d42e..2d6d04b 100644 --- a/src/Manager/CronJobManager.php +++ b/src/Manager/CronJobManager.php @@ -33,6 +33,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\HttpKernel\KernelInterface; use whatwedo\CronBundle\CronJob\CronInterface; +use whatwedo\CronBundle\CronJob\CronJobInterface; use whatwedo\CronBundle\Exception\CronJobNotFoundException; class CronJobManager @@ -77,7 +78,7 @@ public function getCronJob(string $class): CronInterface throw new CronJobNotFoundException($class); } - public function getCommandByCronJob(CronInterface $cronJob): Command + public function getCommandByCronJob(CronJobInterface $cronJob): Command { return $this->consoleApplication->find($cronJob->getCommand()); } diff --git a/src/Manager/ExecutionManager.php b/src/Manager/ExecutionManager.php index 6095f9e..fa372e6 100644 --- a/src/Manager/ExecutionManager.php +++ b/src/Manager/ExecutionManager.php @@ -147,9 +147,12 @@ public function getLastExecution(CronInterface $cronJob): ?Execution return $this->repository->findLastExecution($cronJob); } - public function getPendingExecution(CronInterface $cronJob) + /** + * @return Execution[] + */ + public function getPendingExecution(CronInterface $cronJob): array { - return $this->repository->findPendingExcecution($cronJob); + return $this->repository->findPendingExecution($cronJob); } protected function schedule(CronInterface $cronJob): void @@ -174,14 +177,14 @@ protected function cleanupStale(): void $executions = $this->repository->findByState(Execution::STATE_RUNNING); foreach ($executions as $execution) { $this->logger->debug(sprintf('Checking execution state with id %d. (%s)', $execution->getPid(), $execution->getJob())); - if (! posix_kill($execution->getPid(), 0)) { + if ($execution->getPid() && ! posix_kill($execution->getPid(), 0)) { $this->em->refresh($execution); if ($execution->getState() === Execution::STATE_RUNNING) { $this->logger->warning(sprintf('Marking execution with id %d as stale. (%s)', $execution->getPid(), $execution->getJob())); $execution ->setState(Execution::STATE_STALE) ->setPid(null); - $this->em->flush($execution); + $this->em->flush(); } } } diff --git a/src/Repository/ExecutionRepository.php b/src/Repository/ExecutionRepository.php index 5cd9aea..29dbf52 100644 --- a/src/Repository/ExecutionRepository.php +++ b/src/Repository/ExecutionRepository.php @@ -34,6 +34,9 @@ use whatwedo\CronBundle\CronJob\CronInterface; use whatwedo\CronBundle\Entity\Execution; +/** + * @extends ServiceEntityRepository + */ class ExecutionRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) @@ -44,7 +47,7 @@ public function __construct(ManagerRegistry $registry) /** * @return Execution[] */ - public function findByState(string $state) + public function findByState(string $state): array { return $this->createQueryBuilder('e') ->where('e.state = :state') @@ -54,7 +57,10 @@ public function findByState(string $state) ->getResult(); } - public function findByJob(CronInterface $cronJob) + /** + * @return Execution[] + */ + public function findByJob(CronInterface $cronJob): array { return $this->createQueryBuilder('e') ->where('e.job = :job') @@ -77,20 +83,10 @@ public function findLastExecution(CronInterface $cronJob): ?Execution ->getOneOrNullResult(); } - public function findNonPendingExcecution(CronInterface $cronJob) - { - return $this->createQueryBuilder('e') - ->where('e.job = :job') - ->andWhere('e.state != :statePending') - ->orderBy('e.startedAt', 'DESC') - ->setParameter('job', $cronJob::class) - ->setParameter('statePending', Execution::STATE_PENDING) - ->getQuery() - ->disableResultCache() - ->getResult(); - } - - public function findPendingExcecution(CronInterface $cronJob) + /** + * @return Execution[] + */ + public function findPendingExecution(CronInterface $cronJob): array { return $this->createQueryBuilder('e') ->where('e.job = :job') @@ -102,7 +98,7 @@ public function findPendingExcecution(CronInterface $cronJob) ->getResult(); } - public function deletePendingJob(CronInterface $cronJob) + public function deletePendingJob(CronInterface $cronJob): int { return $this->createQueryBuilder('e') ->delete() @@ -115,7 +111,7 @@ public function deletePendingJob(CronInterface $cronJob) ; } - public function deleteSuccessfulJobs(\DateTimeInterface $retention, $limit = null) + public function deleteSuccessfulJobs(\DateTimeInterface $retention): int { return $this->createQueryBuilder('e') ->delete() @@ -129,7 +125,7 @@ public function deleteSuccessfulJobs(\DateTimeInterface $retention, $limit = nul ; } - public function deleteNotSuccessfulJobs(\DateTimeInterface $retention, $limit = null) + public function deleteNotSuccessfulJobs(\DateTimeInterface $retention): int { return $this->createQueryBuilder('e') ->delete() @@ -147,7 +143,7 @@ public function deleteNotSuccessfulJobs(\DateTimeInterface $retention, $limit = ; } - public function deleteExecutions(CronInterface $cronJob, string $state) + public function deleteExecutions(CronInterface $cronJob, string $state): int { $states = match ($state) { 'successful' => [ @@ -160,6 +156,7 @@ public function deleteExecutions(CronInterface $cronJob, string $state) 'pending' => [ Execution::STATE_PENDING, ], + default => [], }; $queryBuilder = $this->createQueryBuilder('e') diff --git a/src/Resources/views/show.html.twig b/src/Resources/views/show.html.twig index 819187b..a7297cf 100644 --- a/src/Resources/views/show.html.twig +++ b/src/Resources/views/show.html.twig @@ -5,19 +5,6 @@ {{ bootstrap_icon('list', { class: 'inline mr-1 h-4 w-4' }) }} {{ 'whatwedo_cronjob.action.back_list'|trans }} - {% if activable %} - {% if cronjob.isActive %} - - {{ 'whatwedo_cronjob.action.deactivate'|trans }} - - {% else %} - - {{ 'whatwedo_cronjob.action.activate'|trans }} - - {% endif %} - {% endif %} {% if allwedToRun %} {{ bootstrap_icon('play-fill', { class: 'inline mr-1 h-4 w-4' }) }} diff --git a/tests/App/public/index.php b/tests/App/public/index.php index 611b5a0..8b68550 100644 --- a/tests/App/public/index.php +++ b/tests/App/public/index.php @@ -15,7 +15,7 @@ } $trustedProxies = $_SERVER['TRUSTED_PROXIES']; if ($trustedProxies ?? $_ENV['TRUSTED_PROXIES'] ?? false) { - Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); + Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO); } $trustedHosts = $_SERVER['TRUSTED_HOSTS']; @@ -23,7 +23,7 @@ Request::setTrustedHosts([$trustedHosts]); } -$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); +$kernel = new Kernel(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); diff --git a/tests/Browser/ControllerTest.php b/tests/Browser/ControllerTest.php index 1dcc14c..654462b 100644 --- a/tests/Browser/ControllerTest.php +++ b/tests/Browser/ControllerTest.php @@ -14,7 +14,7 @@ class ControllerTest extends KernelTestCase { use HasBrowser; - public function testIndex() + public function testIndex(): void { $this->browser() ->visit('/index') @@ -22,7 +22,7 @@ public function testIndex() ; } - public function testShow() + public function testShow(): void { $this->browser() ->visit('/show/'.DemoCron::class) @@ -30,15 +30,17 @@ public function testShow() ; } - public function testExecution() + public function testExecution(): void { $execution = new Execution(); $execution->setState(Execution::STATE_FINISHED); $execution->setJob(DemoCron::class); $execution->setExitCode(0); - self::getContainer()->get(EntityManagerInterface::class)->persist($execution); - self::getContainer()->get(EntityManagerInterface::class)->flush(); + /** @var EntityManagerInterface $em */ + $em = self::getContainer()->get(EntityManagerInterface::class); + $em->persist($execution); + $em->flush(); $this->browser() ->visit('/excecution/'.$execution->getId()) diff --git a/tests/Cron/CronBundleCommandTest.php b/tests/Cron/CronBundleCommandTest.php index 0caf0fb..8b5d036 100644 --- a/tests/Cron/CronBundleCommandTest.php +++ b/tests/Cron/CronBundleCommandTest.php @@ -11,7 +11,7 @@ class CronBundleCommandTest extends KernelTestCase { use InteractsWithConsole; - public function testListCommand() + public function testListCommand(): void { $this->executeConsoleCommand('whatwedo:cron:list') ->assertSuccessful() // command exit code is 0 @@ -19,35 +19,35 @@ public function testListCommand() ; } - public function testInfoCommand() + public function testInfoCommand(): void { $this->executeConsoleCommand("whatwedo:cron:info whatwedo\\\CronBundle\\\Tests\\\App\\\CronJob\\\DemoCron") ->assertSuccessful() // command exit code is 0 ; } - public function testExecuteCommand() + public function testExecuteCommand(): void { $this->executeConsoleCommand("whatwedo:cron:execute whatwedo\\\CronBundle\\\Tests\\\App\\\CronJob\\\DemoCron") ->assertSuccessful() // command exit code is 0 ; } - public function testCheckCommand() + public function testCheckCommand(): void { $this->executeConsoleCommand('whatwedo:cron:check') ->assertSuccessful() // command exit code is 0 ; } - public function testCleanupCommand() + public function testCleanupCommand(): void { $this->executeConsoleCommand('whatwedo:cron:cleanup') ->assertSuccessful() // command exit code is 0 ; } - public function testSchedulerCommand() + public function testSchedulerCommand(): void { $this->executeConsoleCommand('whatwedo:cron:scheduler --max-runtime 60') ->assertSuccessful() // command exit code is 0