8000 Merge branch '5.0' · symfony/symfony@be0e04b · GitHub
[go: up one dir, main page]

Skip to content

Commit be0e04b

Browse files
Merge branch '5.0'
* 5.0: (21 commits) fix merge CS [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer stop using deprecated Doctrine persistence classes [Cache] Fix wrong classname in deprecation message Fix regex lookahead syntax in ApplicationTest Fixed syntax in comment [SecurityBundle][FirewallMap] Remove unused property [Messenger][AMQP] Use delivery_mode=2 by default [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of #28462" [FrameworkBundle][Secrets] Hook configured local dotenv file [DI] Improve performance of processDefinition fix redis multi host dsn not recognized fix constructor argument type declaration Fix invalid Windows path normalization [Validator][ConstraintValidator] Safe fail on invalid timezones [DoctrineBridge] Fixed submitting invalid ids when using queries with limit [FrameworkBundle] Add info & example to auto_mapping config ...
2 parents 8c80c5b + 525d7bf commit be0e04b

File tree

39 files changed

+331
-76
lines changed
  • Tests/Compiler
  • HttpFoundation/Session/Storage/Handler
  • Messenger
  • Security
  • Serializer
  • Validator
  • 39 files changed

    +331
    -76
    lines changed

    src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

    Lines changed: 15 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -50,6 +50,21 @@ public function getEntities()
    5050
    */
    5151
    public function getEntitiesByIds(string $identifier, array $values)
    5252
    {
    53+
    if (null !== $this->queryBuilder->getMaxResults() || null !== $this->queryBuilder->getFirstResult()) {
    54+
    // an offset or a limit would apply on results including the where clause with submitted id values
    55+
    // that could make invalid choices valid
    56+
    $choices = [];
    57+
    $metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));
    58+
    59+
    foreach ($this->getEntities() as $entity) {
    60+
    if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) {
    61+
    $choices[] = $entity;
    62+
    }
    63+
    }
    64+
    65+
    return $choices;
    66+
    }
    67+
    5368
    $qb = clone $this->queryBuilder;
    5469
    $alias = current($qb->getRootAliases());
    5570
    $parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;

    src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

    Lines changed: 25 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -953,6 +953,31 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
    953953
    $this->assertNull($field->getData());
    954954
    }
    955955

    956+
    public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifierWithLimit()
    957+
    {
    958+
    $entity1 = new SingleIntIdEntity(1, 'Foo');
    959+
    $entity2 = new SingleIntIdEntity(2, 'Bar');
    960+
    $entity3 = new SingleIntIdEntity(3, 'Baz');
    961+
    962+
    $this->persist([$entity1, $entity2, $entity3]);
    963+
    964+
    $repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
    965+
    966+
    $field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
    967+
    57AE 'em' => 'default',
    968+
    'class' => self::SINGLE_IDENT_CLASS,
    969+
    'query_builder' => $repository->createQueryBuilder('e')
    970+
    ->where('e.id IN (1, 2, 3)')
    971+
    ->setMaxResults(1),
    972+
    'choice_label' => 'name',
    973+
    ]);
    974+
    975+
    $field->submit('3');
    976+
    977+
    $this->assertFalse($field->isSynchronized());
    978+
    $this->assertNull($field->getData());
    979+
    }
    980+
    956981
    public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleAssocIdentifier()
    957982
    {
    958983
    $innerEntity1 = new SingleIntIdNoToStringEntity(1, 'InFoo');

    src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php

    Lines changed: 38 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,13 +14,17 @@
    1414
    use Symfony\Component\Config\ConfigCache;
    1515
    use Symfony\Component\Config\FileLocator;
    1616
    use Symfony\Component\Console\Command\Command;
    17+
    use Symfony\Component\Console\Exception\RuntimeException;
    1718
    use Symfony\Component\Console\Input\InputInterface;
    1819
    use Symfony\Component\Console\Output\OutputInterface;
    20+
    use Symfony\Component\Console\Style\SymfonyStyle;
    1921
    use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
    2022
    use Symfony\Component\DependencyInjection\Compiler\PassConfig;
    23+
    use Symfony\Component\DependencyInjection\Container;
    2124
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    2225
    use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
    2326
    use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
    27+
    use Symfony\Component\HttpKernel\Kernel;
    2428

    2529
    final class ContainerLintCommand extends Command
    2630
    {
    @@ -47,13 +51,18 @@ protected function configure()
    4751
    */
    4852
    protected function execute(InputInterface $input, OutputInterface $output): int
    4953
    {
    50-
    $container = $this->getContainerBuilder();
    54+
    $io = new SymfonyStyle($input, $output);
    55+
    $errorIo = $io->getErrorStyle();
    5156

    52-
    $container->setParameter('container.build_hash', 'lint_container');
    53-
    $container->setParameter('container.build_time', time());
    54-
    $container->setParameter('container.build_id', 'lint_container');
    57+
    try {
    58+
    $container = $this->getContainerBuilder();
    59+
    } catch (RuntimeException $e) {
    60+
    $errorIo->error($e->getMessage());
    61+
    62+
    return 2;
    63+
    }
    5564

    56-
    $container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);
    65+
    $container->setParameter('container.build_time', time());
    5766

    5867
    $container->compile();
    5968

    @@ -67,22 +76,44 @@ private function getContainerBuilder(): ContainerBuilder
    6776
    }
    6877

    6978
    $kernel = $this->getApplication()->getKernel();
    79+
    $kernelContainer = $kernel->getContainer();
    80+
    81+
    if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
    82+
    if (!$kernel instanceof Kernel) {
    83+
    throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', \get_class($kernel), Kernel::class));
    84+
    }
    7085

    71-
    if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
    7286
    $buildContainer = \Closure::bind(function (): ContainerBuilder {
    7387
    $this->initializeBundles();
    7488

    7589
    return $this->buildContainer();
    7690
    }, $kernel, \get_class($kernel));
    7791
    $container = $buildContainer();
    92+
    93+
    $skippedIds = [];
    7894
    } else {
    79-
    (new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
    95+
    if (!$kernelContainer instanceof Container) {
    96+
    throw new RuntimeException(sprintf('This command does not support the application container: "%s" does not extend "%s".', \get_class($kernelContainer), Container::class));
    97+
    }
    98+
    99+
    (new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernelContainer->getParameter('debug.container.dump'));
    80100

    81101
    $refl = new \ReflectionProperty($parameterBag, 'resolved');
    82102
    $refl->setAccessible(true);
    83103
    $refl->setValue($parameterBag, true);
    104+
    105+
    $passConfig = $container->getCompilerPassConfig();
    106+
    $passConfig->setRemovingPasses([]);
    107+
    $passConfig->setAfterRemovingPasses([]);
    108+
    109+
    $skippedIds = $kernelContainer->getRemovedIds();
    84110
    }
    85111

    112+
    $container->setParameter('container.build_hash', 'lint_container');
    113+
    $container->setParameter('container.build_id', 'lint_container');
    114+
    115+
    $container->addCompilerPass(new CheckTypeDeclarationsPass(true, $skippedIds), PassConfig::TYPE_AFTER_REMOVING, -100);
    116+
    86117
    return $this->containerBuilder = $container;
    87118
    }
    88119
    }

    src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

    Lines changed: 6 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -130,7 +130,7 @@ private function addSecretsSection(ArrayNodeDefinition $rootNode)
    130130
    ->canBeDisabled()
    131131
    ->children()
    132132
    ->scalarNode('vault_directory')->defaultValue('%kernel.project_dir%/config/secrets/%kernel.environment%')->cannotBeEmpty()->end()
    133-
    ->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.local')->end()
    133+
    ->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.environment%.local')->end()
    134134
    ->scalarNode('decryption_env_var')->defaultValue('base64:default::SYMFONY_DECRYPTION_SECRET')->end()
    135135
    ->end()
    136136
    ->end()
    @@ -724,6 +724,11 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
    724724
    ->end()
    725725
    ->end()
    726726
    ->arrayNode('auto_mapping')
    727+
    ->info('A collection of namespaces for which auto-mapping will be enabled.')
    728+
    ->example([
    729+
    'App\\Entity\\' => [],
    730+
    'App\\WithSpecificLoaders\\' => ['validator.property_info_loader'],
    731+
    ])
    727732
    ->useAttributeAsKey('namespace')
    728733
    ->normalizeKeys(false)
    729734
    ->beforeNormalization()

    src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1353,7 +1353,9 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
    13531353

    13541354
    $container->getDefinition('secrets.vault')->replaceArgument(0, $config['vault_directory']);
    13551355

    1356-
    if (!$config['local_dotenv_file']) {
    1356+
    if ($config['local_dotenv_file']) {
    1357+
    $container->getDefinition('secrets.local_vault')->replaceArgument(0, $config['local_dotenv_file']);
    1358+
    } else {
    13571359
    $container->removeDefinition('secrets.local_vault');
    13581360
    }
    13591361

    src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -7,12 +7,12 @@
    77
    <services>
    88
    <service id="secrets.vault" class="Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault">
    99
    <tag name="container.env_var_loader" />
    10-
    <argument>%kernel.project_dir%/config/secrets/%kernel.environment%</argument>
    11-
    <argument>%env(base64:default::SYMFONY_DECRYPTION_SECRET)%</argument>
    10+
    <argument />
    11+
    <argument />
    1212
    </service>
    1313

    1414
    <service id="secrets.local_vault" class="Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault">
    15-
    <argument>%kernel.project_dir%/.env.local</argument>
    15+
    <argument />
    1616
    </service>
    1717
    </services>
    1818
    </container>

    src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -504,7 +504,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
    504504
    'secrets' => [
    505505
    'enabled' => true,
    506506
    'vault_directory' => '%kernel.project_dir%/config/secrets/%kernel.environment%',
    507-
    'local_dotenv_file' => '%kernel.project_dir%/.env.local',
    507+
    'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.environment%.local',
    508508
    'decryption_env_var' => 'base64:default::SYMFONY_DECRYPTION_SECRET',
    509509
    ],
    510510
    ];

    src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php

    Lines changed: 0 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -26,13 +26,11 @@ class FirewallMap implements FirewallMapInterface
    2626
    {
    2727
    private $container;
    2828
    private $map;
    29-
    private $contexts;
    3029

    3130
    public function __construct(ContainerInterface $container, iterable $map)
    3231
    {
    3332
    $this->container = $container;
    3433
    $this->map = $map;
    35-
    $this->contexts = new \SplObjectStorage();
    3634
    }
    3735

    3836
    public function getListeners(Request $request)

    src/Symfony/Component/Console/Tests/ApplicationTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -616,7 +616,7 @@ public function testFindAlternativeCommands()
    616616
    $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
    617617
    $this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
    618618
    $this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
    619-
    $this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
    619+
    $this->assertNotRegExp('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
    620620
    }
    621621
    }
    622622

    src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

    Lines changed: 10 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -42,23 +42,30 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
    4242
    private const SCALAR_TYPES = ['int', 'float', 'bool', 'string'];
    4343

    4444
    private $autoload;
    45+
    private $skippedIds;
    4546

    4647
    private $expressionLanguage;
    4748

    4849
    /**
    49-
    * @param bool $autoload Whether services who's class in not loaded should be checked or not.
    50-
    * Defaults to false to save loading code during compilation.
    50+
    * @param bool $autoload Whether services who's class in not loaded should be checked or not.
    51+
    * Defaults to false to save loading code during compilation.
    52+
    * @param array $skippedIds An array indexed by the service ids to skip
    5153
    */
    52-
    public function __construct(bool $autoload = false)
    54+
    public function __construct(bool $autoload = false, array $skippedIds = [])
    5355
    {
    5456
    $this->autoload = $autoload;
    57+
    $this->skippedIds = $skippedIds;
    5558
    }
    5659

    5760
    /**
    5861
    * {@inheritdoc}
    5962
    */
    6063
    protected function processValue($value, $isRoot = false)
    6164
    {
    65+
    if (isset($this->skippedIds[$this->currentId])) {
    66+
    return $value;
    67+
    }
    68+
    6269
    if (!$value instanceof Definition || $value->hasErrors()) {
    6370
    return parent::processValue($value, $isRoot);
    6471
    }

    src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -63,9 +63,10 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
    6363
    $instanceofTags = [];
    6464
    $instanceofCalls = [];
    6565
    $instanceofBindings = [];
    66+
    $reflectionClass = null;
    6667

    6768
    foreach ($conditionals as $interface => $instanceofDefs) {
    68-
    if ($interface !== $class && (!$container->getReflectionClass($class, false))) {
    69+
    if ($interface !== $class && !(null === $reflectionClass ? $reflectionClass = ($container->getReflectionClass($class, false) ?: false) : $reflectionClass)) {
    6970
    continue;
    7071
    }
    7172

    src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

    Lines changed: 12 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -669,4 +669,16 @@ public function testProcessHandleNotFoundEnvPlaceholder()
    669669

    670670
    $this->addToAssertionCount(1);
    671671
    }
    672+
    673+
    public function testProcessSkipSkippedIds()
    674+
    {
    675+
    $container = new ContainerBuilder();
    676+
    $container
    677+
    ->register('foobar', BarMethodCall::class)
    678+
    ->addMethodCall('setArray', ['a string']);
    679+
    680+
    (new CheckTypeDeclarationsPass(true, ['foobar' => true]))->process($container);
    681+
    682+
    $this->addToAssertionCount(1);
    683+
    }
    672684
    }

    src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -50,13 +50,13 @@ public static function createHandler($connection): AbstractSessionHandler
    5050
    case 0 === strpos($connection, 'file://'):
    5151
    return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7)));
    5252

    53-
    case 0 === strpos($connection, 'redis://'):
    54-
    case 0 === strpos($connection, 'rediss://'):
    55-
    case 0 === strpos($connection, 'memcached://'):
    53+
    case 0 === strpos($connection, 'redis:'):
    54+
    case 0 === strpos($connection, 'rediss:'):
    55+
    case 0 === strpos($connection, 'memcached:'):
    5656
    if (!class_exists(AbstractAdapter::class)) {
    5757
    throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
    5858
    }
    59-
    $handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
    59+
    $handlerClass = 0 === strpos($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
    6060
    $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
    6161

    6262
    return new $handlerClass($connection);

    src/Symfony/Component/Messenger/Handler/MessageSubscriberInterface.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -28,7 +28,7 @@ interface MessageSubscriberInterface extends MessageHandlerInterface
    2828
    * It can also change the priority per classes.
    2929
    *
    3030
    * yield FirstMessage::class => ['priority' => 0];
    31-
    * yield SecondMessage::class => ['priority => -10];
    31+
    * yield SecondMessage::class => ['priority' => -10];
    3232
    *
    3333
    * It can also specify a method, a priority, a bus and/or a transport per message:
    3434
    *

    src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php

    Lines changed: 21 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -227,7 +227,7 @@ public function testItSetupsTheConnectionWithDefaults()
    227227
    );
    228228

    229229
    $amqpExchange->expects($this->once())->method('declareExchange');
    230-
    $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => []]);
    230+
    $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
    231231
    $amqpQueue->expects($this->once())->method('declareQueue');
    232232
    $amqpQueue->expects($this->once())->method('bind')->with(self::DEFAULT_EXCHANGE_NAME, null);
    233233

    @@ -250,7 +250,7 @@ public function testItSetupsTheConnection()
    250250
    $factory->method('createQueue')->will($this->onConsecutiveCalls($amqpQueue0, $amqpQueue1));
    251251

    252252
    $amqpExchange->expects($this->once())->method('declareExchange');
    253-
    $amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', AMQP_NOPARAM, ['headers' => []]);
    253+
    $amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
    254254
    $amqpQueue0->expects($this->once())->method('declareQueue');
    255255
    $amqpQueue0->expects($this->exactly(2))->method('bind')->withConsecutive(
    256256
    [self::DEFAULT_EXCHANGE_NAME, 'binding_key0'],
    @@ -400,7 +400,7 @@ public function testItDelaysTheMessage()
    400400
    $delayQueue->expects($this->once())->method('declareQueue');
    401401
    $delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__5000');
    402402

    403-
    $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo']]);
    403+
    $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo'], 'delivery_mode' => 2]);
    404404

    405405
    $connection = Connection::fromDsn('amqp://localhost', [], $factory);
    406406
    $connection->publish('{}', ['x-some-headers' => 'foo'], 5000);
    @@ -442,7 +442,7 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
    442442
    $delayQueue->expects($this->once())->method('declareQueue');
    443443
    $delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__120000');
    444444

    445-
    $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000', AMQP_NOPARAM, ['headers' => []]);
    445+
    $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
    446446
    $connection->publish('{}', [], 120000);
    447447
    }
    448448

    @@ -474,12 +474,27 @@ public function testAmqpStampHeadersAreUsed()
    474474
    $amqpExchange = $this->createMock(\AMQPExchange::class)
    475475
    );
    476476

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

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

    483+
    public function testAmqpStampDelireryModeIsUsed()
    484+
    {
    485+
    $factory = new TestAmqpFactory(
    486+
    $this->createMock(\AMQPConnection::class),
    487+
    $this->createMock(\AMQPChannel::class),
    488+
    $this->createMock(\AMQPQueue::class),
    489+
    $amqpExchange = $this->createMock(\AMQPExchange::class)
    490+
    );
    491+
    492+
    $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 1]);
    493+
    494+
    $connection = Connection::fromDsn('amqp://localhost', [], $factory);
    495+
    $connection->publish('body', [], 0, new AmqpStamp(null, AMQP_NOPARAM, ['delivery_mode' => 1]));
    496+
    }
    497+
    483498
    public function testItCanPublishWithTheDefaultRoutingKey()
    484499
    {
    485500
    $factory = new TestAmqpFactory(
    @@ -546,7 +561,7 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument
    546561
    $delayQueue->expects($this->once())->method('declareQueue');
    547562
    $delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages_routing_key_120000');
    548563

    549-
    $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000', AMQP_NOPARAM, ['headers' => []]);
    564+
    $delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
    550565
    $connection->publish('{}', [], 120000, new AmqpStamp('routing_key'));
    551566
    }
    552567

    0 commit comments

    Comments
     (0)
    0