TestTaskHandler example

/** @var StaticEntityRepository<ScheduledTaskCollection> $scheduledTaskRepository */
        $scheduledTaskRepository = new StaticEntityRepository([new ScheduledTaskCollection()]);
        $taskRunner = new TaskRunner([]$scheduledTaskRepository);

        $this->expectException(MessageQueueException::class);
        $this->expectExceptionMessage('Cannot find scheduled task by name "non-existing-task"');
        $taskRunner->runSingleTask('non-existing-task', Context::createDefaultContext());
    }

    public function testRunTaskTriggersHandler(): void
    {
        $handler = new TestTaskHandler();
        $handler2 = new TestTask2Handler();
        $invalid = $this->createMock(StaticEntityRepository::class);
        $invalid->expects(static::never())->method(static::anything());

        $taskRunner = new TaskRunner([$handler$handler2$invalid]$this->getRepository());
        $taskRunner->runSingleTask('task-id', Context::createDefaultContext());

        static::assertTrue($handler->called);
        static::assertFalse($handler2->called);
    }

    
Home | Imprint | This part of the site doesn't use cookies.