RedisSender example

public function testSend()
    {
        $envelope = new Envelope(new DummyMessage('Oy'));
        $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

        $connection = $this->createMock(Connection::class);
        $connection->expects($this->once())->method('add')->with($encoded['body']$encoded['headers'])->willReturn('THE_MESSAGE_ID');

        $serializer = $this->createMock(SerializerInterface::class);
        $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);

        $sender = new RedisSender($connection$serializer);

        /** @var TransportMessageIdStamp $stamp */
        $stamp = $sender->send($envelope)->last(TransportMessageIdStamp::class);

        $this->assertNotNull($stampsprintf('A "%s" stamp should be added', TransportMessageIdStamp::class));
        $this->assertSame('THE_MESSAGE_ID', $stamp->getId());
    }
}

        return $this->getReceiver()->getMessageCount();
    }

    private function getReceiver(): RedisReceiver
    {
        return $this->receiver ??= new RedisReceiver($this->connection, $this->serializer);
    }

    private function getSender(): RedisSender
    {
        return $this->sender ??= new RedisSender($this->connection, $this->serializer);
    }
}
Home | Imprint | This part of the site doesn't use cookies.