diff --git a/src/Jobs.php b/src/Jobs.php index 1698c8b..b541581 100644 --- a/src/Jobs.php +++ b/src/Jobs.php @@ -123,7 +123,7 @@ private function toStringOfStringMap(array $map): array \is_string($value) => $value, \is_bool($value) => $value ? 'true' : 'false', $value instanceof \JsonSerializable, - \is_array($value) => \json_encode($value, \JSON_THROW_ON_ERROR | (empty($value)? \JSON_FORCE_OBJECT : 0)), + \is_array($value) => \json_encode($value, \JSON_THROW_ON_ERROR), default => throw new \InvalidArgumentException( \sprintf('Can not cast to string unrecognized value of type %s', \get_debug_type($value)), ), diff --git a/src/Queue/AMQPCreateInfo.php b/src/Queue/AMQPCreateInfo.php index e55f2a1..883da0b 100644 --- a/src/Queue/AMQPCreateInfo.php +++ b/src/Queue/AMQPCreateInfo.php @@ -84,7 +84,6 @@ public function toArray(): array 'requeue_on_fail' => $this->requeueOnFail, 'durable' => $this->durable, 'consume_all' => $this->consumeAll, - 'queue_headers' => $this->queueHeaders, 'delete_queue_on_stop' => $this->deleteQueueOnStop, 'redial_timeout' => $this->redialTimeout, ]); @@ -93,6 +92,10 @@ public function toArray(): array $result['consumer_id'] = $this->consumerId; } + if ($this->queueHeaders !== []) { + $result['queue_headers'] = $this->queueHeaders; + } + return $result; } } diff --git a/tests/Unit/Queue/AMQPCreateInfoTest.php b/tests/Unit/Queue/AMQPCreateInfoTest.php index 5e0e338..3e44f35 100644 --- a/tests/Unit/Queue/AMQPCreateInfoTest.php +++ b/tests/Unit/Queue/AMQPCreateInfoTest.php @@ -133,4 +133,11 @@ public function testToArray(): void $this->assertEquals($expectedArray, $amqpCreateInfo->toArray()); } + + public function testToArrayWithEmptyQueueHeaders(): void + { + $amqpCreateInfo = new AMQPCreateInfo(name: 'foo'); + + $this->assertArrayNotHasKey('queue_headers', $amqpCreateInfo->toArray()); + } }