From f4c848b712e685d56eb857db848b0563429c9b4b Mon Sep 17 00:00:00 2001 From: Adrian Dumitrache Date: Mon, 15 Apr 2024 19:11:24 +0300 Subject: [PATCH] Resolved code review feedback --- packages/cron-job/CronJobProcessor.php | 18 ++++++++++++++++++ packages/cron-job/Entity/CronJob.php | 14 +++++++------- .../ExecuteCronJobMessageHandlerTest.php | 17 ++++++++--------- packages/cron-job/composer.json | 9 +++++++-- .../Integration/CronJobIntegration.php | 16 +++++----------- 5 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 packages/cron-job/CronJobProcessor.php diff --git a/packages/cron-job/CronJobProcessor.php b/packages/cron-job/CronJobProcessor.php new file mode 100644 index 00000000..59db23e3 --- /dev/null +++ b/packages/cron-job/CronJobProcessor.php @@ -0,0 +1,18 @@ + false])] private bool $active = false; - #[ORM\Column(name: 'command', type: 'string', length: 255, nullable: false)] + #[ORM\Column(name: 'command', type: 'text', nullable: false)] private ?string $command = null; #[ORM\Column(name: 'schedule', type: 'string', length: 255, nullable: true)] private ?string $schedule = null; - #[ORM\Column(name: 'ttl', type: 'int', nullable: false, options: ['default' => 0])] - private int $ttl = 0; + #[ORM\Column(name: 'time_to_live', type: 'int', nullable: false, options: ['default' => 0])] + private int $timeToLive = 0; #[ORM\Column(name: 'priority', type: 'int', nullable: true)] private ?int $priority = null; @@ -110,14 +110,14 @@ public function setSchedule(?string $schedule): self return $this; } - public function getTtl(): int + public function getTimeToLive(): int { - return $this->ttl; + return $this->timeToLive; } - public function setTtl(int $ttl): self + public function setTimeToLive(int $timeToLive): self { - $this->ttl = $ttl; + $this->timeToLive = $timeToLive; return $this; } diff --git a/packages/cron-job/Tests/MessageHandler/ExecuteCronJobMessageHandlerTest.php b/packages/cron-job/Tests/MessageHandler/ExecuteCronJobMessageHandlerTest.php index 16e6dfa9..36a3e28c 100644 --- a/packages/cron-job/Tests/MessageHandler/ExecuteCronJobMessageHandlerTest.php +++ b/packages/cron-job/Tests/MessageHandler/ExecuteCronJobMessageHandlerTest.php @@ -4,9 +4,6 @@ namespace Draw\Component\CronJob\Tests\MessageHandler; -use Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire\AutowiredCompletionAwareInterface; -use Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire\AutowireMock; -use Draw\Bundle\TesterBundle\WebTestCase; use Draw\Component\CronJob\Entity\CronJobExecution; use Draw\Component\CronJob\Event\PostCronJobExecutionEvent; use Draw\Component\CronJob\Event\PreCronJobExecutionEvent; @@ -14,21 +11,23 @@ use Draw\Component\CronJob\MessageHandler\ExecuteCronJobMessageHandler; use Draw\Component\Tester\MockTrait; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; -class ExecuteCronJobMessageHandlerTest extends WebTestCase implements AutowiredCompletionAwareInterface +class ExecuteCronJobMessageHandlerTest extends TestCase { use MockTrait; - #[AutowireMock] - private EventDispatcherInterface&MockObject $eventDispatcher; - private ExecuteCronJobMessageHandler $handler; - public function postAutowire(): void + private EventDispatcherInterface&MockObject $eventDispatcher; + + protected function setUp(): void { + parent::setUp(); + $this->handler = new ExecuteCronJobMessageHandler( - $this->eventDispatcher + $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class) ); } diff --git a/packages/cron-job/composer.json b/packages/cron-job/composer.json index 2cba7a87..c60d2cf1 100644 --- a/packages/cron-job/composer.json +++ b/packages/cron-job/composer.json @@ -11,10 +11,15 @@ } ], "require": { - "php": ">=8.1" + "php": ">=8.1", + "doctrine/orm": "^3.1", + "draw/core": "^0.10.16", + "symfony/event-dispatcher": "^7.0", + "symfony/messenger": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^9.0 || ^10.0", + "draw/tester": "^0.10.16" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/packages/framework-extra-bundle/DependencyInjection/Integration/CronJobIntegration.php b/packages/framework-extra-bundle/DependencyInjection/Integration/CronJobIntegration.php index 56899378..90811273 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Integration/CronJobIntegration.php +++ b/packages/framework-extra-bundle/DependencyInjection/Integration/CronJobIntegration.php @@ -4,8 +4,8 @@ namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration; -use Draw\Component\Console\Command\PurgeExecutionCommand; -use Draw\Component\Console\Entity\Execution; +use Draw\Component\CronJob\CronJobProcessor; +use Draw\Component\CronJob\Entity\CronJob; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; @@ -16,7 +16,7 @@ class CronJobIntegration implements IntegrationInterface, PrependIntegrationInte public function getConfigSectionName(): string { - return 'cron-job'; + return 'cron_job'; } public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void @@ -24,13 +24,7 @@ public function load(array $config, PhpFileLoader $loader, ContainerBuilder $con $this->registerClasses( $loader, $namespace = 'Draw\\Component\\CronJob\\', - $directory = \dirname( - (new \ReflectionClass(PurgeExecutionCommand::class))->getFileName(), - 2 - ), - [ - $directory.'/Output/', - ] + \dirname((new \ReflectionClass(CronJobProcessor::class))->getFileName()) ); $this->renameDefinitions( @@ -49,7 +43,7 @@ public function prepend(ContainerBuilder $container, array $config): void { $this->assertHasExtension($container, 'doctrine'); - $reflection = new \ReflectionClass(Execution::class); + $reflection = new \ReflectionClass(CronJob::class); $container->prependExtensionConfig( 'doctrine',