Skip to content

Commit

Permalink
Resolved code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DumitracheAdrian committed Apr 15, 2024
1 parent 89ccf56 commit f4c848b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
18 changes: 18 additions & 0 deletions packages/cron-job/CronJobProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Draw\Component\CronJob;

use Draw\Component\CronJob\Entity\CronJob;

class CronJobProcessor
{
public function __construct()
{
}

public function process(CronJob $cronJob): void
{
}
}
14 changes: 7 additions & 7 deletions packages/cron-job/Entity/CronJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class CronJob implements \Stringable
#[ORM\Column(name: 'active', type: 'boolean', nullable: false, options: ['default' => 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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,30 @@

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;
use Draw\Component\CronJob\Message\ExecuteCronJobMessage;
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)
);
}

Expand Down
9 changes: 7 additions & 2 deletions packages/cron-job/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,21 +16,15 @@ 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
{
$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(
Expand All @@ -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',
Expand Down

0 comments on commit f4c848b

Please sign in to comment.