InMemoryTransport example

class InMemoryTransportFactory implements TransportFactoryInterface, ResetInterface
{
    /** * @var InMemoryTransport[] */
    private array $createdTransports = [];

    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
    {
        ['serialize' => $serialize] = $this->parseDsn($dsn);

        return $this->createdTransports[] = new InMemoryTransport($serialize ? $serializer : null);
    }

    public function supports(string $dsn, array $options): bool
    {
        return str_starts_with($dsn, 'in-memory://');
    }

    /** * @return void */
    public function reset()
    {
class InMemoryTransportTest extends TestCase
{
    private InMemoryTransport $transport;

    private InMemoryTransport $serializeTransport;

    private SerializerInterface $serializer;

    protected function setUp(): void
    {
        $this->serializer = $this->createMock(SerializerInterface::class);
        $this->transport = new InMemoryTransport();
        $this->serializeTransport = new InMemoryTransport($this->serializer);
    }

    public function testSend()
    {
        $envelope = new Envelope(new \stdClass());
        $this->transport->send($envelope);
        $this->assertEquals([$envelope->with(new TransportMessageIdStamp(1))]$this->transport->getSent());
    }

    public function testSendWithSerialization()
    {
Home | Imprint | This part of the site doesn't use cookies.