BarMessage example

use Symfony\Component\Clock\MockClock;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Scheduler\Messenger\SchedulerTransport;
use Symfony\Component\Scheduler\RecurringMessage;

class SchedulerTest extends AbstractWebTestCase
{
    public function testScheduler()
    {
        $scheduledMessages = [
            RecurringMessage::every('5 minutes', $foo = new FooMessage()new \DateTimeImmutable('2020-01-01T00:00:00Z')),
            RecurringMessage::every('5 minutes', $bar = new BarMessage()new \DateTimeImmutable('2020-01-01T00:01:00Z')),
        ];
        DummySchedule::$recurringMessages = $scheduledMessages;

        $container = self::getContainer();
        $container->set('clock', $clock = new MockClock('2020-01-01T00:09:59Z'));

        $this->assertTrue($container->get('receivers')->has('scheduler_dummy'));
        $this->assertInstanceOf(SchedulerTransport::class$cron = $container->get('receivers')->get('scheduler_dummy'));

        $fetchMessages = static function Dfloat $sleep) use ($clock$cron) {
            if (0 < $sleep) {
                
/** @var AbstractIncrementer $pool */
        $pool = $this->getContainer()
            ->get('shopware.increment.gateway.registry')
            ->get(IncrementGatewayRegistry::MESSAGE_QUEUE_POOL);

        $pool->reset('message_queue_stats');

        /** @var MessageBusInterface $bus */
        $bus = $this->getContainer()->get('messenger.bus.test_shopware');

        $bus->dispatch(new FooMessage());
        $bus->dispatch(new BarMessage());
        $bus->dispatch(new BarMessage());
        $bus->dispatch(new BarMessage());

        $stats = $pool->list('message_queue_stats');
        static::assertEquals(1, $stats[FooMessage::class]['count']);
        static::assertEquals(3, $stats[BarMessage::class]['count']);

        $this->runWorker();

        $stats = $pool->list('message_queue_stats');
        static::assertEquals(0, $stats[FooMessage::class]['count']);
        
Home | Imprint | This part of the site doesn't use cookies.