Skip to content

Commit

Permalink
Throw exception on non-integer values provided as args
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Dec 16, 2018
1 parent dab71ef commit 86595d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,25 @@ public function testSetsParametersOnTheQueueAndExchange()

$amqpQueue->expects($this->once())->method('setArguments')->with(array(
'x-dead-letter-exchange' => 'dead-exchange',
'x-message-ttl' => 100,
'x-delay' => 100,
'x-expires' => 150,
'x-max-length' => 200,
'x-max-length-bytes' => 300,
'x-max-priority' => 4,
'x-message-ttl' => 100,
));

$amqpExchange->expects($this->once())->method('setArguments')->with(array(
'alternate-exchange' => 'alternate',
));

$connection = Connection::fromDsn('amqp://localhost/%2f/messages?queue[arguments][x-dead-letter-exchange]=dead-exchange&queue[arguments][x-message-ttl]=100', array(
$dsn = 'amqp://localhost/%2f/messages?'.
'queue[arguments][x-dead-letter-exchange]=dead-exchange&'.
'queue[arguments][x-message-ttl]=100&'.
'queue[arguments][x-delay]=100&'.
'queue[arguments][x-expires]=150&'
;
$connection = Connection::fromDsn($dsn, array(
'queue' => array(
'arguments' => array(
'x-max-length' => '200',
Expand All @@ -123,6 +131,18 @@ public function testSetsParametersOnTheQueueAndExchange()
$connection->publish('body');
}

public function testSetsParametersOnTheQueueAndExchangeFails()
{
$dsn = 'amqp://localhost/%2f/messages?'.
'queue[arguments][x-dead-letter-exchange]=dead-exchange&'.
'queue[arguments][x-message-ttl]=not-a-number&'
;

$this->expectsException(\InvalidArgumentException::class);
$this->expecteExceptionMessage('Invalid value provided for queue argument x-message-ttl: \'not-a-number\' is not a valid integer value');
Connection::fromDsn($dsn);
}

public function testItUsesANormalConnectionByDefault()
{
$factory = new TestAmqpFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ private static function normalizeQueueOptions(array $queueOptions): array

foreach (self::ARGUMENTS_AS_INTEGER as $key) {
if (array_key_exists($key, $queueOptions['arguments'])) {
if (!\is_numeric($queueOptions['arguments'][$key])) {
throw new \InvalidArgumentException(sprintf(
'Invalid value provided for queue argument %s: %s is not a valid integer value',
$key,
var_export($queueOptions['arguments'][$key], true)
));
}
$queueOptions['arguments'][$key] = (int) $queueOptions['arguments'][$key];
}
}
Expand Down

0 comments on commit 86595d0

Please sign in to comment.