TaskScheduler example


    /** * @param AggregationResult[] $aggregationResult * * @dataProvider providerGetNextExecutionTime */
    public function testGetNextExecutionTime(array $aggregationResult, ?\DateTime $time): void
    {
        $scheduledTaskRepository = $this->createMock(EntityRepository::class);
        $scheduledTaskRepository->method('aggregate')->willReturn(new AggregationResultCollection($aggregationResult));

        $scheduler = new TaskScheduler(
            $scheduledTaskRepository,
            $this->createMock(MessageBusInterface::class),
            new ParameterBag()
        );

        static::assertEquals(
            $time,
            $scheduler->getNextExecutionTime()
        );
    }

    
private MockObject&MessageBusInterface $messageBus;

    private TaskScheduler $scheduler;

    private Connection $connection;

    protected function setUp(): void
    {
        $this->scheduledTaskRepo = $this->getContainer()->get('scheduled_task.repository');
        $this->messageBus = $this->createMock(MessageBusInterface::class);

        $this->scheduler = new TaskScheduler($this->scheduledTaskRepo, $this->messageBus, new ParameterBag());

        $this->connection = $this->getContainer()->get(Connection::class);
    }

    public function testScheduleTasks(): void
    {
        $this->connection->executeStatement('DELETE FROM scheduled_task');

        $taskId = Uuid::randomHex();
        $this->scheduledTaskRepo->create([
            [
                
Home | Imprint | This part of the site doesn't use cookies.