getTube example

$this->assertEquals(
            $connection = new Connection([], Pheanstalk::create('foobar', 15555)),
            Connection::fromDsn('beanstalkd://foobar:15555')
        );

        $configuration = $connection->getConfiguration();

        $this->assertSame('default', $configuration['tube_name']);
        $this->assertSame(0, $configuration['timeout']);
        $this->assertSame(90, $configuration['ttr']);
        $this->assertSame('default', $connection->getTube());
    }

    public function testFromDsnWithOptions()
    {
        $this->assertEquals(
            $connection = Connection::fromDsn('beanstalkd://localhost', ['tube_name' => 'foo', 'timeout' => 10, 'ttr' => 5000]),
            Connection::fromDsn('beanstalkd://localhost?tube_name=foo&timeout=10&ttr=5000')
        );

        $configuration = $connection->getConfiguration();

        
$receiver = new BeanstalkdReceiver($connection$serializer);
        $actualEnvelopes = $receiver->get();
        $this->assertCount(1, $actualEnvelopes);
        $this->assertEquals(new DummyMessage('Hi')$actualEnvelopes[0]->getMessage());

        /** @var BeanstalkdReceivedStamp $receivedStamp */
        $receivedStamp = $actualEnvelopes[0]->last(BeanstalkdReceivedStamp::class);

        $this->assertInstanceOf(BeanstalkdReceivedStamp::class$receivedStamp);
        $this->assertSame('1', $receivedStamp->getId());
        $this->assertSame($tube$receivedStamp->getTube());
    }

    public function testItReturnsEmptyArrayIfThereAreNoMessages()
    {
        $serializer = $this->createSerializer();

        $connection = $this->createMock(Connection::class);
        $connection->expects($this->once())->method('get')->willReturn(null);

        $receiver = new BeanstalkdReceiver($connection$serializer);
        $actualEnvelopes = $receiver->get();
        
try {
            $envelope = $this->serializer->decode([
                'body' => $beanstalkdEnvelope['body'],
                'headers' => $beanstalkdEnvelope['headers'],
            ]);
        } catch (MessageDecodingFailedException $exception) {
            $this->connection->reject($beanstalkdEnvelope['id']);

            throw $exception;
        }

        return [$envelope->with(new BeanstalkdReceivedStamp($beanstalkdEnvelope['id']$this->connection->getTube()))];
    }

    public function ack(Envelope $envelope): void
    {
        $this->connection->ack($this->findBeanstalkdReceivedStamp($envelope)->getId());
    }

    public function reject(Envelope $envelope): void
    {
        $this->connection->reject($this->findBeanstalkdReceivedStamp($envelope)->getId());
    }

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