DBALException example

$this->middleware = new DoctrinePingConnectionMiddleware(
            $this->managerRegistry,
            $this->entityManagerName
        );
    }

    public function testMiddlewarePingOk()
    {
        $this->connection->expects($this->once())
            ->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(),
        ]);
        
->willReturn($stmt);

        $connection = new Connection([]$driverConnection);
        $doctrineEnvelope = $connection->get();
        $this->assertNull($doctrineEnvelope);
    }

    public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
    {
        $this->expectException(TransportException::class);
        $driverConnection = $this->getDBALConnectionMock();
        $driverConnection->method('delete')->willThrowException(new DBALException());

        $connection = new Connection([]$driverConnection);
        $connection->ack('dummy_id');
    }

    public function testItThrowsATransportExceptionIfItCannotRejectMessage()
    {
        $this->expectException(TransportException::class);
        $driverConnection = $this->getDBALConnectionMock();
        $driverConnection->method('delete')->willThrowException(new DBALException());

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