ConsumedByWorkerStamp example

->method('getDatabasePlatform')
            ->will($this->throwException(new DBALException()));

        $this->connection->expects($this->once())
            ->method('close')
        ;
        $this->connection->expects($this->once())
            ->method('connect')
        ;

        $envelope = new Envelope(new \stdClass()[
            new ConsumedByWorkerStamp(),
        ]);
        $this->middleware->handle($envelope$this->getStackMock());
    }

    public function testMiddlewarePingResetEntityManager()
    {
        $this->connection->expects($this->once())
            ->method('getDatabasePlatform')
            ->will($this->throwException(new DBALException()));

        $this->entityManager->expects($this->once())
            
$this->entityManagerName
        );
    }

    public function testMiddlewareCloseConnection()
    {
        $this->connection->expects($this->once())
            ->method('close')
        ;

        $envelope = new Envelope(new \stdClass()[
            new ConsumedByWorkerStamp(),
        ]);
        $this->middleware->handle($envelope$this->getStackMock());
    }

    public function testInvalidEntityManagerThrowsException()
    {
        $managerRegistry = $this->createMock(ManagerRegistry::class);
        $managerRegistry
            ->method('getManager')
            ->with('unknown_manager')
            ->will($this->throwException(new \InvalidArgumentException()));

        

        $router = $this->createMock(RequestContextAwareInterface::class);
        $context = new RequestContext('', 'POST', 'github.com');

        $router
            ->expects($this->once())
            ->method('getContext')
            ->willReturn($context);

        $middleware = new RouterContextMiddleware($router);
        $envelope = new Envelope(new \stdClass()[
            new ConsumedByWorkerStamp(),
            new RouterContextStamp('', 'GET', 'symfony.com', 'https', 80, 443, '/', ''),
        ]);

        $nextMiddleware = $this->createMock(MiddlewareInterface::class);
        $nextMiddleware
            ->expects($this->once())
            ->method('handle')
            ->willReturnCallback(function DEnvelope $envelope, StackInterface $stack) use ($context): Envelope {
                $this->assertSame('symfony.com', $context->getHost());

                return $envelope;
            })
return;
        }

        $acked = false;
        $ack = function DEnvelope $envelope, \Throwable $e = null) use ($transportName, &$acked) {
            $acked = true;
            $this->acks[] = [$transportName$envelope$e];
        };

        try {
            $e = null;
            $envelope = $this->bus->dispatch($envelope->with(new ReceivedStamp($transportName)new ConsumedByWorkerStamp()new AckStamp($ack)));
        } catch (\Throwable $e) {
        }

        $noAutoAckStamp = $envelope->last(NoAutoAckStamp::class);

        if (!$acked && !$noAutoAckStamp) {
            $this->acks[] = [$transportName$envelope$e];
        } elseif ($noAutoAckStamp) {
            $this->unacks[$noAutoAckStamp->getHandlerDescriptor()->getBatchHandler()] = [$envelope->withoutAll(AckStamp::class)$transportName];
        }

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