<?php namespace Kastilyo\RabbitHole\Spec; use kahlan\plugin\Stub; use kahlan\Arg; use AMQPEnvelope; use Eloquent\Liberator\Liberator; use Kastilyo\RabbitHole\Subscriber\SubscriberInterface; use Kastilyo\RabbitHole\Subscriber\SubscriberTrait; use Kastilyo\RabbitHole\Exceptions\ImplementationException; use Kastilyo\RabbitHole\AMQP\QueueBuilder; use Kastilyo\RabbitHole\AMQP\ExchangeBuilder; describe('BatchSubscriber', function () { beforeEach(function () { $this->amqp_connection = Helper::getAMQPConnection(); $this->batch_subscriber = new BatchSubscriber($this->amqp_connection); }); describe('->processMessage', function () { beforeEach(function () { $this->envelopes = array_map(function ($ignore) { $envelope = Helper::getAMQPEnvelope(); Stub::on($envelope)->method('getDeliveryTag')->andReturn('some_delivery_tag'); return $envelope; }, array_fill(0, $this->batch_subscriber->getBatchCount(), null)); Stub::on($this->batch_subscriber)->method('acknowledgeMessage'); // process three ahead of time $this->batch_subscriber->processMessage($this->envelopes[0]); $this->batch_subscriber->processMessage($this->envelopes[1]); $this->batch_subscriber->processMessage($this->envelopes[2]); });
<?php namespace Kastilyo\RabbitHole\Spec; use kahlan\plugin\Stub; use kahlan\Arg; use Kastilyo\RabbitHole\Exceptions\InvalidPropertyException; use Kastilyo\RabbitHole\AMQP\ExchangeBuilder; describe('ExchangeBuilder', function () { beforeEach(function () { Helper::initializeAMQPStubs(); $this->connection = Helper::getAMQPConnection(); $this->exchange_builder = new ExchangeBuilder($this->connection); }); context('->get', function () { beforeEach(function () { $this->exchange_name = 'some_exchange'; $this->exchange_builder->setName($this->exchange_name); }); it("makes the connection if it hasn't been made yet", function () { expect($this->connection)->toReceive('connect'); $this->exchange_builder->get(); }); it("doesn't make the connection if it's been made already", function () { Stub::on($this->connection)->method('isConnected')->andReturn(true); expect($this->connection)->not->toReceive('connect'); $this->exchange_builder->get(); }); context('Exchange declaration', function () { it('sets the name of the exchange', function () { expect('AMQPExchange')->toReceive('setName')->with($this->exchange_name);