Skip to content

Commit

Permalink
Merge branch '4.4'
Browse files Browse the repository at this point in the history
* 4.4: (53 commits)
  Fix Twig 1.x compatibility
  Deprecating templateExists method
  [Translator] Improve farsi(persian) translations for Form
  [Validator] Fix Changelog for #31511
  [Lock][Console] bump lock requirement in console
  [Lock] minor: add missing alias for PersistenStoreInterface
  Improve fa translations
  Dynamic bundle assets
  [Lock] rename and deprecate Factory into LockFactory
  [Debug] Restoring back the state of the Debug component (1st step)
  Spell "triggering" properly
  [Lock] Fix tests
  Added tests to cover the possibility of having scalars as services.
  fixed CS
  [Lock] Split \"StoreInterface\" into multiple interfaces with less responsability
  [VarDumper] Let browsers trigger their own search on double CMD/CTRL + F hit
  [Validator] Allow to use property paths to get limits in range constraint
  Fix missing deprecations
  fixed tests on old PHP versions
  [FrameworkBundle] Inform the user when save_path will be ignored
  ...
  • Loading branch information
nicolas-grekas committed Jul 11, 2019
2 parents c7c5be1 + 8a8f532 commit 800feb1
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 64 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/MessengerPass.php
Expand Up @@ -219,7 +219,7 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $type));
}

return [(string) $parameters[0]->getType()];
return [$parameters[0]->getType()->getName()];
}

private function registerReceivers(ContainerBuilder $container, array $busIds)
Expand Down
15 changes: 15 additions & 0 deletions Tests/Transport/AmqpExt/ConnectionTest.php
Expand Up @@ -418,6 +418,21 @@ public function testObfuscatePasswordInDsn()
$connection->channel();
}

public function testAmqpStampHeadersAreUsed()
{
$factory = new TestAmqpFactory(
$this->createMock(\AMQPConnection::class),
$this->createMock(\AMQPChannel::class),
$this->createMock(\AMQPQueue::class),
$amqpExchange = $this->createMock(\AMQPExchange::class)
);

$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y']]);

$connection = Connection::fromDsn('amqp://localhost', [], $factory);
$connection->publish('body', ['Foo' => 'X'], 0, new AmqpStamp(null, AMQP_NOPARAM, ['headers' => ['Bar' => 'Y']]));
}

public function testItCanPublishWithTheDefaultRoutingKey()
{
$factory = new TestAmqpFactory(
Expand Down
113 changes: 69 additions & 44 deletions Tests/Transport/Doctrine/ConnectionTest.php
Expand Up @@ -157,61 +157,86 @@ private function getSchemaSynchronizerMock()
/**
* @dataProvider buildConfigurationProvider
*/
public function testBuildConfiguration($dsn, $options, $expectedManager, $expectedTableName, $expectedRedeliverTimeout, $expectedQueue)
public function testBuildConfiguration($dsn, $options, $expectedConnection, $expectedTableName, $expectedRedeliverTimeout, $expectedQueue, $expectedAutoSetup)
{
$config = Connection::buildConfiguration($dsn, $options);
$this->assertEquals($expectedManager, $config['connection']);
$this->assertEquals($expectedConnection, $config['connection']);
$this->assertEquals($expectedTableName, $config['table_name']);
$this->assertEquals($expectedRedeliverTimeout, $config['redeliver_timeout']);
$this->assertEquals($expectedQueue, $config['queue_name']);
$this->assertEquals($expectedAutoSetup, $config['auto_setup']);
}

public function buildConfigurationProvider()
{
return [
[
'dsn' => 'doctrine://default',
'options' => [],
'expectedManager' => 'default',
'expectedTableName' => 'messenger_messages',
'expectedRedeliverTimeout' => 3600,
'expectedQueue' => 'default',
],
// test options from options array
[
'dsn' => 'doctrine://default',
'options' => [
'table_name' => 'name_from_options',
'redeliver_timeout' => 1800,
'queue_name' => 'important',
],
'expectedManager' => 'default',
'expectedTableName' => 'name_from_options',
'expectedRedeliverTimeout' => 1800,
'expectedQueue' => 'important',
],
// tests options from dsn
[
'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal',
'options' => [],
'expectedManager' => 'default',
'expectedTableName' => 'name_from_dsn',
'expectedRedeliverTimeout' => 1200,
'expectedQueue' => 'normal',
yield 'no options' => [
'dsn' => 'doctrine://default',
'options' => [],
'expectedConnection' => 'default',
'expectedTableName' => 'messenger_messages',
'expectedRedeliverTimeout' => 3600,
'expectedQueue' => 'default',
'expectedAutoSetup' => true,
];

yield 'test options array' => [
'dsn' => 'doctrine://default',
'options' => [
'table_name' => 'name_from_options',
'redeliver_timeout' => 1800,
'queue_name' => 'important',
'auto_setup' => false,
],
// test options from options array wins over options from dsn
[
'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal',
'options' => [
'table_name' => 'name_from_options',
'redeliver_timeout' => 1800,
'queue_name' => 'important',
],
'expectedManager' => 'default',
'expectedTableName' => 'name_from_options',
'expectedRedeliverTimeout' => 1800,
'expectedQueue' => 'important',
'expectedConnection' => 'default',
'expectedTableName' => 'name_from_options',
'expectedRedeliverTimeout' => 1800,
'expectedQueue' => 'important',
'expectedAutoSetup' => false,
];

yield 'options from dsn' => [
'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal&auto_setup=false',
'options' => [],
'expectedConnection' => 'default',
'expectedTableName' => 'name_from_dsn',
'expectedRedeliverTimeout' => 1200,
'expectedQueue' => 'normal',
'expectedAutoSetup' => false,
];

yield 'options from options array wins over options from dsn' => [
'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal&auto_setup=true',
'options' => [
'table_name' => 'name_from_options',
'redeliver_timeout' => 1800,
'queue_name' => 'important',
'auto_setup' => false,
],
'expectedConnection' => 'default',
'expectedTableName' => 'name_from_options',
'expectedRedeliverTimeout' => 1800,
'expectedQueue' => 'important',
'expectedAutoSetup' => false,
];

yield 'options from dsn with falsey boolean' => [
'dsn' => 'doctrine://default?auto_setup=0',
'options' => [],
'expectedConnection' => 'default',
'expectedTableName' => 'messenger_messages',
'expectedRedeliverTimeout' => 3600,
'expectedQueue' => 'default',
'expectedAutoSetup' => false,
];

yield 'options from dsn with thruthy boolean' => [
'dsn' => 'doctrine://default?auto_setup=1',
'options' => [],
'expectedConnection' => 'default',
'expectedTableName' => 'messenger_messages',
'expectedRedeliverTimeout' => 3600,
'expectedQueue' => 'default',
'expectedAutoSetup' => true,
];
}

Expand Down
4 changes: 2 additions & 2 deletions Transport/AmqpExt/AmqpStamp.php
Expand Up @@ -11,13 +11,13 @@

namespace Symfony\Component\Messenger\Transport\AmqpExt;

use Symfony\Component\Messenger\Stamp\StampInterface;
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;

/**
* @author Guillaume Gammelin <ggammelin@gmail.com>
* @author Samuel Roze <samuel.roze@gmail.com>
*/
final class AmqpStamp implements StampInterface
final class AmqpStamp implements NonSendableStampInterface
{
private $routingKey;
private $flags;
Expand Down
15 changes: 7 additions & 8 deletions Transport/AmqpExt/Connection.php
Expand Up @@ -189,9 +189,7 @@ public function publish(string $body, array $headers = [], int $delay = 0, AmqpS
$this->exchange(),
$body,
$this->getRoutingKeyForMessage($amqpStamp),
[
'headers' => $headers,
],
$headers,
$amqpStamp
);
}
Expand Down Expand Up @@ -221,20 +219,21 @@ private function publishWithDelay(string $body, array $headers, int $delay, Amqp
$this->getDelayExchange(),
$body,
$this->getRoutingKeyForDelay($delay, $routingKey),
[
'headers' => $headers,
],
$headers,
$amqpStamp
);
}

private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $attributes = [], AmqpStamp $amqpStamp = null)
private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $headers = [], AmqpStamp $amqpStamp = null)
{
$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];
$attributes['headers'] = array_merge($headers, $attributes['headers'] ?? []);

$exchange->publish(
$body,
$routingKey,
$amqpStamp ? $amqpStamp->getFlags() : AMQP_NOPARAM,
array_merge($amqpStamp ? $amqpStamp->getAttributes() : [], $attributes)
$attributes
);
}

Expand Down
15 changes: 6 additions & 9 deletions Transport/Doctrine/Connection.php
Expand Up @@ -74,22 +74,19 @@ public static function buildConfiguration($dsn, array $options = []): array
parse_str($components['query'], $query);
}

$configuration = [
'connection' => $components['host'],
'table_name' => $options['table_name'] ?? ($query['table_name'] ?? self::DEFAULT_OPTIONS['table_name']),
'queue_name' => $options['queue_name'] ?? ($query['queue_name'] ?? self::DEFAULT_OPTIONS['queue_name']),
'redeliver_timeout' => $options['redeliver_timeout'] ?? ($query['redeliver_timeout'] ?? self::DEFAULT_OPTIONS['redeliver_timeout']),
'auto_setup' => $options['auto_setup'] ?? ($query['auto_setup'] ?? self::DEFAULT_OPTIONS['auto_setup']),
];
$configuration = ['connection' => $components['host']];
$configuration += $options + $query + self::DEFAULT_OPTIONS;

$configuration['auto_setup'] = filter_var($configuration['auto_setup'], FILTER_VALIDATE_BOOLEAN);

// check for extra keys in options
$optionsExtraKeys = array_diff(array_keys($options), array_keys($configuration));
$optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS));
if (0 < \count($optionsExtraKeys)) {
throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s]', implode(', ', $optionsExtraKeys), implode(', ', self::DEFAULT_OPTIONS)));
}

// check for extra keys in options
$queryExtraKeys = array_diff(array_keys($query), array_keys($configuration));
$queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS));
if (0 < \count($queryExtraKeys)) {
throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s]', implode(', ', $queryExtraKeys), implode(', ', self::DEFAULT_OPTIONS)));
}
Expand Down

0 comments on commit 800feb1

Please sign in to comment.