diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29307d8..54bbfa4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,7 @@ jobs: matrix: php-version: ['7.4', '8.0', '8.1' ] symfony-version: ['^4.4', '^5.0'] + amqp-version: ['1.11.0', '2.1.2'] fail-fast: false steps: - uses: actions/checkout@master @@ -16,7 +17,7 @@ jobs: with: php-version: ${{ matrix.php-version }} coverage: xdebug2 - extensions: amqp + extensions: amqp-${{ matrix.amqp-version }} - name: Install symfony version from matrix env: SYMFONY_VERSION: ${{ matrix.symfony-version }} diff --git a/src/AmqpBundle/Amqp/Consumer.php b/src/AmqpBundle/Amqp/Consumer.php index 766e7ad..08eaad0 100644 --- a/src/AmqpBundle/Amqp/Consumer.php +++ b/src/AmqpBundle/Amqp/Consumer.php @@ -34,7 +34,6 @@ public function __construct(\AMQPQueue $queue, array $queueOptions) public function getMessage(int $flags = AMQP_AUTOACK): ?\AMQPEnvelope { $envelope = $this->call($this->queue, 'get', [$flags]); - $envelope = $envelope === false ? null : $envelope; if ($this->eventDispatcher) { $preRetrieveEvent = new PreRetrieveEvent($envelope); @@ -49,13 +48,13 @@ public function getMessage(int $flags = AMQP_AUTOACK): ?\AMQPEnvelope /** * Acknowledge the receipt of a message. * - * @param string $deliveryTag delivery tag of last message to ack + * @param int $deliveryTag delivery tag of last message to ack * @param int $flags AMQP_MULTIPLE or AMQP_NOPARAM * * @throws \AMQPChannelException if the channel is not open * @throws \AMQPConnectionException if the connection to the broker was lost */ - public function ackMessage(string $deliveryTag, int $flags = AMQP_NOPARAM): bool + public function ackMessage(int $deliveryTag, int $flags = AMQP_NOPARAM): void { if ($this->eventDispatcher) { $ackEvent = new AckEvent($deliveryTag, $flags); @@ -63,19 +62,19 @@ public function ackMessage(string $deliveryTag, int $flags = AMQP_NOPARAM): bool $this->eventDispatcher->dispatch($ackEvent,AckEvent::NAME); } - return $this->call($this->queue, 'ack', [$deliveryTag, $flags]); + $this->call($this->queue, 'ack', [$deliveryTag, $flags]); } /** * Mark a message as explicitly not acknowledged. * - * @param string $deliveryTag delivery tag of last message to nack + * @param int $deliveryTag delivery tag of last message to nack * @param int $flags AMQP_NOPARAM or AMQP_REQUEUE to requeue the message(s) * * @throws \AMQPConnectionException if the connection to the broker was lost * @throws \AMQPChannelException if the channel is not open */ - public function nackMessage(string $deliveryTag, int $flags = AMQP_NOPARAM): bool + public function nackMessage(int $deliveryTag, int $flags = AMQP_NOPARAM): void { if ($this->eventDispatcher) { $nackEvent = new NackEvent($deliveryTag, $flags); @@ -83,7 +82,7 @@ public function nackMessage(string $deliveryTag, int $flags = AMQP_NOPARAM): boo $this->eventDispatcher->dispatch($nackEvent, NackEvent::NAME); } - return $this->call($this->queue, 'nack', [$deliveryTag, $flags]); + $this->call($this->queue, 'nack', [$deliveryTag, $flags]); } /** @@ -92,7 +91,7 @@ public function nackMessage(string $deliveryTag, int $flags = AMQP_NOPARAM): boo * @throws \AMQPChannelException if the channel is not open * @throws \AMQPConnectionException if the connection to the broker was lost */ - public function purge(): bool + public function purge(): int { if ($this->eventDispatcher) { $purgeEvent = new PurgeEvent($this->queue); diff --git a/src/AmqpBundle/Amqp/Producer.php b/src/AmqpBundle/Amqp/Producer.php index 3af083f..0760691 100644 --- a/src/AmqpBundle/Amqp/Producer.php +++ b/src/AmqpBundle/Amqp/Producer.php @@ -33,7 +33,7 @@ public function __construct(\AMQPExchange $exchange, array $exchangeOptions) * timestamp, expiration, type or reply_to * @param array $routingKeys If set, overrides the Producer 'routing_keys' for this message * - * @return bool tRUE on success or FALSE on failure + * @return bool TRUE on success or throws on failure * * @throws \AMQPExchangeException on failure * @throws \AMQPChannelException if the channel is not open @@ -63,16 +63,17 @@ public function publishMessage(string $message, int $flags = AMQP_NOPARAM, array } if (!$routingKeys) { - return $this->call($this->exchange, 'publish', [$message, null, $flags, $attributes]); + $this->call($this->exchange, 'publish', [$message, null, $flags, $attributes]); + + return true; } // Publish the message for each routing keys - $success = true; foreach ($routingKeys as $routingKey) { - $success &= $this->call($this->exchange, 'publish', [$message, $routingKey, $flags, $attributes]); + $this->call($this->exchange, 'publish', [$message, $routingKey, $flags, $attributes]); } - return (bool) $success; + return true; } public function getExchange(): \AMQPExchange diff --git a/src/AmqpBundle/Event/AckEvent.php b/src/AmqpBundle/Event/AckEvent.php index 518f6b5..849b36c 100644 --- a/src/AmqpBundle/Event/AckEvent.php +++ b/src/AmqpBundle/Event/AckEvent.php @@ -11,17 +11,17 @@ class AckEvent extends Event { const NAME = 'amqp.ack'; - private string $deliveryTag; + private int $deliveryTag; private int $flags; - public function __construct(string $deliveryTag, int $flags) + public function __construct(int $deliveryTag, int $flags) { $this->deliveryTag = $deliveryTag; $this->flags = $flags; } - public function getDeliveryTag(): string + public function getDeliveryTag(): int { return $this->deliveryTag; } diff --git a/src/AmqpBundle/Event/NackEvent.php b/src/AmqpBundle/Event/NackEvent.php index 46a02d7..eb977d8 100644 --- a/src/AmqpBundle/Event/NackEvent.php +++ b/src/AmqpBundle/Event/NackEvent.php @@ -11,16 +11,16 @@ class NackEvent extends Event { const NAME = 'amqp.nack'; - private string $deliveryTag; + private int $deliveryTag; private int $flags; - public function __construct(string $deliveryTag, int $flags) + public function __construct(int $deliveryTag, int $flags) { $this->deliveryTag = $deliveryTag; $this->flags = $flags; } - public function getDeliveryTag(): string + public function getDeliveryTag(): int { return $this->deliveryTag; } diff --git a/src/AmqpBundle/Sandbox/NullConnection.php b/src/AmqpBundle/Sandbox/NullConnection.php index 77c69e8..1998f6d 100644 --- a/src/AmqpBundle/Sandbox/NullConnection.php +++ b/src/AmqpBundle/Sandbox/NullConnection.php @@ -10,48 +10,42 @@ class NullConnection extends \AMQPConnection /** * {@inheritdoc} */ - public function connect() + public function connect(): void { - return true; } /** * {@inheritdoc} */ - public function pconnect() + public function pconnect(): void { - return true; } /** * {@inheritdoc} */ - public function pdisconnect() + public function pdisconnect(): void { - return true; } /** * {@inheritdoc} */ - public function disconnect() + public function disconnect(): void { - return true; } /** * {@inheritdoc} */ - public function reconnect() + public function reconnect(): void { - return true; } /** * {@inheritdoc} */ - public function preconnect() + public function preconnect(): void { - return true; } } diff --git a/src/AmqpBundle/Sandbox/NullEnvelope.php b/src/AmqpBundle/Sandbox/NullEnvelope.php index 588c63c..381fb6b 100644 --- a/src/AmqpBundle/Sandbox/NullEnvelope.php +++ b/src/AmqpBundle/Sandbox/NullEnvelope.php @@ -7,87 +7,33 @@ */ class NullEnvelope extends \AMQPEnvelope { - /** - * @var string - */ - private $body; - /** - * @var string - */ - private $routingKey; - /** - * @var string - */ - private $deliveryTag; - /** - * @var string - */ - private $deliveryMode; - /** - * @var bool - */ - private $redelivery; - /** - * @var string - */ - private $contentType; - /** - * @var string - */ - private $contentEncoding; - /** - * @var string - */ - private $type; - /** - * @var string - */ - private $timestamp; - /** - * @var int - */ - private $priority; - /** - * @var string - */ - private $expiration; - /** - * @var string - */ - private $userId; - /** - * @var string - */ - private $appId; - /** - * @var string - */ - private $messageId; - /** - * @var string - */ - private $replyTo; - /** - * @var string - */ - private $correlationId; - /** - * @var array - */ - private $headers; + private string $body; + private string $routingKey; + private int $deliveryTag; + private int $deliveryMode; + private bool $redelivery; + private string $contentType; + private string $contentEncoding; + private string $type; + private string $timestamp; + private int $priority; + private string $expiration; + private string $userId; + private string $appId; + private string $messageId; + private string $replyTo; + private string $correlationId; + private array $headers; /** * {@inheritdoc} */ - public function getBody() + public function getBody(): string { return $this->body; } - /** - * @param string $body - */ - public function setBody($body) + public function setBody(string $body): void { $this->body = $body; } @@ -95,15 +41,12 @@ public function setBody($body) /** * {@inheritdoc} */ - public function getRoutingKey() + public function getRoutingKey(): string { return $this->routingKey; } - /** - * @param string $routingKey - */ - public function setRoutingKey($routingKey) + public function setRoutingKey(string $routingKey): void { $this->routingKey = $routingKey; } @@ -111,15 +54,12 @@ public function setRoutingKey($routingKey) /** * {@inheritdoc} */ - public function getDeliveryTag() + public function getDeliveryTag(): int { return $this->deliveryTag; } - /** - * @param string $deliveryTag - */ - public function setDeliveryTag($deliveryTag) + public function setDeliveryTag(int $deliveryTag): void { $this->deliveryTag = $deliveryTag; } @@ -127,15 +67,12 @@ public function setDeliveryTag($deliveryTag) /** * {@inheritdoc} */ - public function getDeliveryMode() + public function getDeliveryMode(): int { return $this->deliveryMode; } - /** - * @param string $deliveryMode - */ - public function setDeliveryMode($deliveryMode) + public function setDeliveryMode(int $deliveryMode): void { $this->deliveryMode = $deliveryMode; } @@ -143,15 +80,12 @@ public function setDeliveryMode($deliveryMode) /** * {@inheritdoc} */ - public function isRedelivery() + public function isRedelivery(): bool { return $this->redelivery; } - /** - * @param bool $redelivery - */ - public function setRedelivery($redelivery) + public function setRedelivery(bool $redelivery): void { $this->redelivery = $redelivery; } @@ -159,15 +93,12 @@ public function setRedelivery($redelivery) /** * {@inheritdoc} */ - public function getContentType() + public function getContentType(): string { return $this->contentType; } - /** - * @param string $contentType - */ - public function setContentType($contentType) + public function setContentType(string $contentType): void { $this->contentType = $contentType; } @@ -175,15 +106,12 @@ public function setContentType($contentType) /** * {@inheritdoc} */ - public function getContentEncoding() + public function getContentEncoding(): string { return $this->contentEncoding; } - /** - * @param string $contentEncoding - */ - public function setContentEncoding($contentEncoding) + public function setContentEncoding(string $contentEncoding): void { $this->contentEncoding = $contentEncoding; } @@ -191,15 +119,12 @@ public function setContentEncoding($contentEncoding) /** * {@inheritdoc} */ - public function getType() + public function getType(): string { return $this->type; } - /** - * @param string $type - */ - public function setType($type) + public function setType(string $type): void { $this->type = $type; } @@ -207,15 +132,12 @@ public function setType($type) /** * {@inheritdoc} */ - public function getTimestamp() + public function getTimestamp(): ?int { return $this->timestamp; } - /** - * @param string $timestamp - */ - public function setTimestamp($timestamp) + public function setTimestamp(string $timestamp): void { $this->timestamp = $timestamp; } @@ -223,15 +145,12 @@ public function setTimestamp($timestamp) /** * {@inheritdoc} */ - public function getPriority() + public function getPriority(): int { return $this->priority; } - /** - * @param int $priority - */ - public function setPriority($priority) + public function setPriority(int $priority): void { $this->priority = $priority; } @@ -239,15 +158,12 @@ public function setPriority($priority) /** * {@inheritdoc} */ - public function getExpiration() + public function getExpiration(): string { return $this->expiration; } - /** - * @param string $expiration - */ - public function setExpiration($expiration) + public function setExpiration(string $expiration): void { $this->expiration = $expiration; } @@ -255,15 +171,12 @@ public function setExpiration($expiration) /** * {@inheritdoc} */ - public function getUserId() + public function getUserId(): string { return $this->userId; } - /** - * @param string $userId - */ - public function setUserId($userId) + public function setUserId(string $userId): void { $this->userId = $userId; } @@ -271,15 +184,12 @@ public function setUserId($userId) /** * {@inheritdoc} */ - public function getAppId() + public function getAppId(): string { return $this->appId; } - /** - * @param string $appId - */ - public function setAppId($appId) + public function setAppId(string $appId): void { $this->appId = $appId; } @@ -287,15 +197,12 @@ public function setAppId($appId) /** * {@inheritdoc} */ - public function getMessageId() + public function getMessageId(): string { return $this->messageId; } - /** - * @param string $messageId - */ - public function setMessageId($messageId) + public function setMessageId(string $messageId): void { $this->messageId = $messageId; } @@ -303,15 +210,12 @@ public function setMessageId($messageId) /** * {@inheritdoc} */ - public function getReplyTo() + public function getReplyTo(): string { return $this->replyTo; } - /** - * @param string $replyTo - */ - public function setReplyTo($replyTo) + public function setReplyTo(string $replyTo): void { $this->replyTo = $replyTo; } @@ -319,15 +223,12 @@ public function setReplyTo($replyTo) /** * {@inheritdoc} */ - public function getCorrelationId() + public function getCorrelationId(): string { return $this->correlationId; } - /** - * @param string $correlationId - */ - public function setCorrelationId($correlationId) + public function setCorrelationId(string $correlationId): void { $this->correlationId = $correlationId; } @@ -335,7 +236,7 @@ public function setCorrelationId($correlationId) /** * {@inheritdoc} */ - public function getHeaders() + public function getHeaders(): array { return $this->headers; } @@ -343,7 +244,7 @@ public function getHeaders() /** * @param array $headers */ - public function setHeaders($headers) + public function setHeaders(array $headers): void { $this->headers = $headers; } @@ -351,8 +252,8 @@ public function setHeaders($headers) /** * {@inheritdoc} */ - public function getHeader($headerKey) + public function getHeader(string $headerName): ?string { - return isset($this->headers[$headerKey]) ? $this->headers[$headerKey] : false; + return $this->headers[$headerName] ?? null; } } diff --git a/src/AmqpBundle/Sandbox/NullQueue.php b/src/AmqpBundle/Sandbox/NullQueue.php index d5a5d15..97b4f1f 100644 --- a/src/AmqpBundle/Sandbox/NullQueue.php +++ b/src/AmqpBundle/Sandbox/NullQueue.php @@ -35,19 +35,19 @@ public function enqueue(\AMQPEnvelope $envelope = null) /** * {@inheritdoc} */ - public function get($flags = AMQP_NOPARAM) + public function get($flags = AMQP_NOPARAM): ?\AMQPEnvelope { if (!$this->envelopes->isEmpty()) { return $this->envelopes->dequeue(); - } else { - return false; } + + return null; } /** * {@inheritdoc} */ - public function declareQueue() + public function declareQueue(): int { return $this->envelopes->count(); } diff --git a/src/AmqpBundle/Tests/Units/Amqp/Consumer.php b/src/AmqpBundle/Tests/Units/Amqp/Consumer.php index 9360834..8965e50 100644 --- a/src/AmqpBundle/Tests/Units/Amqp/Consumer.php +++ b/src/AmqpBundle/Tests/Units/Amqp/Consumer.php @@ -26,8 +26,9 @@ public function testConstruct() public function testGetMessageAutoAck() { + $msgList = ['wait' => [1 => 'message1', '2' => 'message2']]; $this - ->if($msgList = ['wait' => ['m1' => 'message1', 'm2' => 'message2']]) + ->if($msgList) ->and($queue = $this->getQueue($msgList)) ->and($consumer = new Base($queue, [])) // First message : auto ack @@ -35,12 +36,12 @@ public function testGetMessageAutoAck() ->isInstanceOf('\AMQPEnvelope') ->string($message->getBody()) ->isEqualTo('message1') - ->string($message->getDeliveryTag()) - ->isEqualTo('m1') + ->integer($message->getDeliveryTag()) + ->isEqualTo(1) ->array($msgList['wait']) - ->isEqualTo(['m2' => 'message2']) + ->isEqualTo([2 => 'message2']) ->array($msgList['ack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['unack']) ->isEmpty() @@ -49,12 +50,12 @@ public function testGetMessageAutoAck() ->isInstanceOf('\AMQPEnvelope') ->string($message->getBody()) ->isEqualTo('message2') - ->string($message->getDeliveryTag()) - ->isEqualTo('m2') + ->integer($message->getDeliveryTag()) + ->isEqualTo(2) ->array($msgList['wait']) ->isEmpty() ->array($msgList['ack']) - ->isEqualTo(['m1' => 'message1', 'm2' => 'message2']) + ->isEqualTo([1 => 'message1', 2 => 'message2']) ->array($msgList['unack']) ->isEmpty() @@ -71,7 +72,7 @@ public function testGetMessageAutoAck() public function testGetMessageManualAck() { $this - ->if($msgList = ['wait' => ['m1' => 'message1']]) + ->if($msgList = ['wait' => [1 => 'message1']]) ->and($queue = $this->getQueue($msgList)) ->and($consumer = new Base($queue, [])) // First message : manual ack @@ -79,58 +80,56 @@ public function testGetMessageManualAck() ->isInstanceOf('\AMQPEnvelope') ->string($message->getBody()) ->isEqualTo('message1') - ->string($message->getDeliveryTag()) - ->isEqualTo('m1') + ->integer($message->getDeliveryTag()) + ->isEqualTo(1) // Check data ->array($msgList['wait']) ->isEmpty() ->array($msgList['unack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['ack']) ->isEmpty() // Ack (unknown delivery id) - ->boolean($message = $consumer->ackMessage(12345)) - ->isFalse() - ->mock($queue) - ->call('ack') - ->withArguments(12345) - ->once() + ->and($message = $consumer->ackMessage(12345)) + ->variable($message) + ->isNull() + ->mock($queue) + ->call('ack') + ->withArguments(12345) + ->once() // Check data ->array($msgList['wait']) ->isEmpty() ->array($msgList['unack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['ack']) ->isEmpty() // Ack (known delivery id) - ->boolean($message = $consumer->ackMessage('m1')) - ->isTrue() - ->mock($queue) - ->call('ack') - ->withArguments('m1') - ->once() + ->and($message = $consumer->ackMessage(1)) + ->variable($message) + ->isNull() + ->mock($queue) + ->call('ack') + ->withArguments(1) + ->once() // Check data ->array($msgList['wait']) ->isEmpty() ->array($msgList['ack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['unack']) - ->isEmpty() - - // Ack (old delivery id) - ->boolean($message = $consumer->ackMessage('m1')) - ->isFalse(); + ->isEmpty(); } public function testGetMessageManualNack() { $this - ->if($msgList = ['wait' => ['m1' => 'message1']]) + ->if($msgList = ['wait' => [1 => 'message1']]) ->and($queue = $this->getQueue($msgList)) ->and($consumer = new Base($queue, [])) // First message : manual ack @@ -138,44 +137,46 @@ public function testGetMessageManualNack() ->isInstanceOf('\AMQPEnvelope') ->string($message->getBody()) ->isEqualTo('message1') - ->string($message->getDeliveryTag()) - ->isEqualTo('m1') + ->integer($message->getDeliveryTag()) + ->isEqualTo(1) // Check data ->array($msgList['wait']) ->isEmpty() ->array($msgList['unack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['ack']) ->isEmpty() // Nack (unknown delivery id) - ->boolean($message = $consumer->nackMessage(12345)) - ->isFalse() - ->mock($queue) - ->call('nack') - ->withArguments(12345) - ->once() + ->and($message = $consumer->nackMessage(12345)) + ->variable($message) + ->isNull() + ->mock($queue) + ->call('nack') + ->withArguments(12345) + ->once() // Check data ->array($msgList['wait']) ->isEmpty() ->array($msgList['unack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['ack']) ->isEmpty() // Nack and requeue (known delivery id) - ->boolean($message = $consumer->nackMessage('m1', AMQP_REQUEUE)) - ->isTrue() - ->mock($queue) - ->call('nack') - ->withArguments('m1') - ->once() + ->and($message = $consumer->nackMessage(1, AMQP_REQUEUE)) + ->variable($message) + ->isNull() + ->mock($queue) + ->call('nack') + ->withArguments(1) + ->once() // Check data ->array($msgList['wait']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['ack']) ->isEmpty() ->array($msgList['unack']) @@ -186,20 +187,21 @@ public function testGetMessageManualNack() ->isInstanceOf('\AMQPEnvelope') ->string($message->getBody()) ->isEqualTo('message1') - ->string($message->getDeliveryTag()) - ->isEqualTo('m1') + ->integer($message->getDeliveryTag()) + ->isEqualTo(1) // Check data ->array($msgList['wait']) ->isEmpty() ->array($msgList['unack']) - ->isEqualTo(['m1' => 'message1']) + ->isEqualTo([1 => 'message1']) ->array($msgList['ack']) ->isEmpty() // Nack and forget (known delivery id) - ->boolean($message = $consumer->nackMessage('m1')) - ->isTrue() + ->and($message = $consumer->nackMessage(1)) + ->variable($message) + ->isNull() // Check data ->array($msgList['wait']) @@ -210,19 +212,19 @@ public function testGetMessageManualNack() ->isEmpty() // Nack (old delivery id) - ->boolean($message = $consumer->nackMessage('m1')) - ->isFalse(); + ->variable($message = $consumer->nackMessage(1)) + ->isEqualTo(null); } public function testPurge() { $this - ->if($msgList = ['wait' => ['m1' => 'message1']]) + ->if($msgList = ['wait' => [1 => 'message1']]) ->and($queue = $this->getQueue($msgList)) ->and($consumer = new Base($queue, [])) // Purge the queue - ->boolean($consumer->purge()) - ->isTrue() + ->integer($consumer->purge()) + ->isEqualTo(1) ->mock($queue) ->call('purge') ->once() @@ -244,7 +246,7 @@ public function testGetMessageCurrentCount() { $this ->if($msgList = [ - 'wait' => ['m1' => 'message1', 'm2' => 'message2'], + 'wait' => [1 => 'message1', 2 => 'message2'], 'flags' => AMQP_DURABLE | AMQP_EXCLUSIVE | AMQP_AUTODELETE, ]) ->and($queue = $this->getQueue($msgList)) @@ -313,7 +315,8 @@ protected function getQueue(&$msgList = []) // Simulate a simple queue reset($msgList['wait']); $key = key($msgList['wait']); - $msg = array_shift($msgList['wait']); + $msg = reset($msgList['wait']); + unset($msgList['wait'][$key]); if (!$key) { return null; diff --git a/src/AmqpBundle/Tests/Units/Amqp/Producer.php b/src/AmqpBundle/Tests/Units/Amqp/Producer.php index a5854d6..df6e346 100644 --- a/src/AmqpBundle/Tests/Units/Amqp/Producer.php +++ b/src/AmqpBundle/Tests/Units/Amqp/Producer.php @@ -72,8 +72,11 @@ public function testSendMessagesError() ->and($producer = new Base($exchange, $exchangeOptions)) ->boolean($producer->publishMessage('message1')) ->isTrue() - ->boolean($producer->publishMessage('error')) - ->isFalse() + ->exception( + function() use($producer) { + $producer->publishMessage('error'); + } + )->isInstanceOf(\AMQPExchangeException::class) ->array($msgList) ->isEqualTo([ ['message1', 'routing_test', AMQP_NOPARAM, $exchangeOptions['publish_attributes']], @@ -182,7 +185,7 @@ protected function getExchange(&$msgList = []) $exchange->getMockController()->publish = function ($message, $routing_key, $flags = AMQP_NOPARAM, array $attributes = []) use (&$msgList) { if (($message == 'error') && ($routing_key == 'error')) { - return false; + throw new \AMQPExchangeException(); } $msgList[] = [$message, $routing_key, $flags, $attributes]; diff --git a/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPChannel.php b/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPChannel.php index 935d1ec..759cd4a 100644 --- a/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPChannel.php +++ b/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPChannel.php @@ -11,15 +11,15 @@ public function __construct(\AMQPConnection $amqp_connection) { } - public function qos($prefetchSize, $prefetchCount, $global = NULL) + public function qos(int $size, int $count, bool $global = NULL): void { } - public function setPrefetchSize($count){ - + public function setPrefetchSize(int $size): void + { } - public function setPrefetchCount($count){ - + public function setPrefetchCount(int $count): void + { } } diff --git a/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPExchange.php b/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPExchange.php index 04040b7..dc5917f 100644 --- a/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPExchange.php +++ b/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPExchange.php @@ -11,7 +11,7 @@ public function __construct(\AMQPChannel $amqp_channel) { } - public function declareExchange() + public function declareExchange(): void { } } diff --git a/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPQueue.php b/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPQueue.php index 9beb77f..a1d481a 100644 --- a/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPQueue.php +++ b/src/AmqpBundle/Tests/Units/Factory/Mock/MockAMQPQueue.php @@ -11,11 +11,12 @@ public function __construct(\AMQPChannel $amqp_channel) { } - public function bind($exchange_name, $routing_key = null, $arguments = array()) + public function bind(string $exchange_name, string $routing_key = null, array $arguments = array()): void { } - public function declareQueue() + public function declareQueue(): int { + return 1; } }