From 6c982e1c84254a7df1f1e856bba95c22a91c5caf Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Fri, 14 Dec 2018 12:15:30 +0000 Subject: [PATCH 1/5] Fix TreeBuilder in Symfony 4.2 A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0. --- .../DependencyInjection/Configuration.php | 4 +- .../DependencyInjection/Configuration.php | 4 +- .../TransportFactoryTest.php | 52 +++++++++---------- pkg/simple-client/SimpleClient.php | 4 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php index 9703e6284..51c94b60c 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php +++ b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php @@ -12,8 +12,8 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('enqueue_async_event_dispatcher'); + $tb = new TreeBuilder('enqueue_async_event_dispatcher'); + $rootNode = $tb->getRootNode(); $rootNode->children() ->scalarNode('context_service')->isRequired()->cannotBeEmpty()->end() diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index d7b3ba3a1..ecc40d42e 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -24,8 +24,8 @@ public function __construct(bool $debug) public function getConfigTreeBuilder(): TreeBuilder { - $tb = new TreeBuilder(); - $rootNode = $tb->root('enqueue'); + $tb = new TreeBuilder('enqueue'); + $rootNode = $tb->getRootNode(); $rootNode ->requiresAtLeastOneElement() diff --git a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php index 6cc02b697..5f96c721c 100644 --- a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php @@ -37,8 +37,8 @@ public function testThrowIfEmptyNameGivenOnConstruction() public function testShouldAllowAddConfigurationAsStringDsn() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -59,8 +59,8 @@ public function testShouldAllowAddConfigurationAsStringDsn() */ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -76,8 +76,8 @@ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() public function testShouldSetNullTransportIfNullGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -93,8 +93,8 @@ public function testShouldSetNullTransportIfNullGiven() public function testShouldSetNullTransportIfEmptyStringGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -110,8 +110,8 @@ public function testShouldSetNullTransportIfEmptyStringGiven() public function testShouldSetNullTransportIfEmptyArrayGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -127,8 +127,8 @@ public function testShouldSetNullTransportIfEmptyArrayGiven() public function testThrowIfEmptyDsnGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -140,8 +140,8 @@ public function testThrowIfEmptyDsnGiven() public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -159,8 +159,8 @@ public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTime() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -178,8 +178,8 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTi public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSameTime() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -196,8 +196,8 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSame public function testShouldAllowSetFactoryClass() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -214,8 +214,8 @@ public function testShouldAllowSetFactoryClass() public function testShouldAllowSetFactoryService() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -232,8 +232,8 @@ public function testShouldAllowSetFactoryService() public function testShouldAllowSetConnectionFactoryClass() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -250,8 +250,8 @@ public function testShouldAllowSetConnectionFactoryClass() public function testThrowIfExtraOptionGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); diff --git a/pkg/simple-client/SimpleClient.php b/pkg/simple-client/SimpleClient.php index 4e3d8e9d6..fcaa52d03 100644 --- a/pkg/simple-client/SimpleClient.php +++ b/pkg/simple-client/SimpleClient.php @@ -306,8 +306,8 @@ public function build(array $configs): void private function createConfiguration(): NodeInterface { - $tb = new TreeBuilder(); - $rootNode = $tb->root('enqueue'); + $tb = new TreeBuilder('enqueue'); + $rootNode = $tb->getRootNode(); $rootNode ->beforeNormalization() From 99cd93387e144b565e305bf19b422589d65e32aa Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Fri, 14 Dec 2018 12:27:16 +0000 Subject: [PATCH 2/5] BC fix. --- .../DependencyInjection/Configuration.php | 7 +- .../DependencyInjection/Configuration.php | 7 +- .../TransportFactoryTest.php | 91 ++++++++++++++++--- pkg/simple-client/SimpleClient.php | 7 +- 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php index 51c94b60c..2deb06a1f 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php +++ b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php @@ -13,7 +13,12 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $tb = new TreeBuilder('enqueue_async_event_dispatcher'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('enqueue_async_event_dispatcher'); + } $rootNode->children() ->scalarNode('context_service')->isRequired()->cannotBeEmpty()->end() diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index ecc40d42e..074ea8267 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -25,7 +25,12 @@ public function __construct(bool $debug) public function getConfigTreeBuilder(): TreeBuilder { $tb = new TreeBuilder('enqueue'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('enqueue'); + } $rootNode ->requiresAtLeastOneElement() diff --git a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php index 5f96c721c..7b76eeffd 100644 --- a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php @@ -38,7 +38,12 @@ public function testThrowIfEmptyNameGivenOnConstruction() public function testShouldAllowAddConfigurationAsStringDsn() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -60,7 +65,12 @@ public function testShouldAllowAddConfigurationAsStringDsn() public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -77,7 +87,12 @@ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() public function testShouldSetNullTransportIfNullGiven() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -94,7 +109,12 @@ public function testShouldSetNullTransportIfNullGiven() public function testShouldSetNullTransportIfEmptyStringGiven() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -111,7 +131,12 @@ public function testShouldSetNullTransportIfEmptyStringGiven() public function testShouldSetNullTransportIfEmptyArrayGiven() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -128,7 +153,12 @@ public function testShouldSetNullTransportIfEmptyArrayGiven() public function testThrowIfEmptyDsnGiven() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -141,7 +171,12 @@ public function testThrowIfEmptyDsnGiven() public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -160,7 +195,12 @@ public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTime() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); @@ -179,7 +219,12 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTi public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSameTime() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -197,7 +242,12 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSame public function testShouldAllowSetFactoryClass() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -215,7 +265,12 @@ public function testShouldAllowSetFactoryClass() public function testShouldAllowSetFactoryService() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -233,7 +288,12 @@ public function testShouldAllowSetFactoryService() public function testShouldAllowSetConnectionFactoryClass() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -251,7 +311,12 @@ public function testShouldAllowSetConnectionFactoryClass() public function testThrowIfExtraOptionGiven() { $tb = new TreeBuilder('foo'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('foo'); + } $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); diff --git a/pkg/simple-client/SimpleClient.php b/pkg/simple-client/SimpleClient.php index fcaa52d03..dd0eb7466 100644 --- a/pkg/simple-client/SimpleClient.php +++ b/pkg/simple-client/SimpleClient.php @@ -307,7 +307,12 @@ public function build(array $configs): void private function createConfiguration(): NodeInterface { $tb = new TreeBuilder('enqueue'); - $rootNode = $tb->getRootNode(); + + if (method_exists($tb, 'getRootNode')) { + $rootNode = $tb->getRootNode(); + } else { + $rootNode = $tb->root('enqueue'); + } $rootNode ->beforeNormalization() From 1f7dc9e12ad0e319fe8e700b37170206e3803a89 Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Fri, 14 Dec 2018 13:03:59 +0000 Subject: [PATCH 3/5] Further BC fix --- .../DependencyInjection/Configuration.php | 6 +- .../DependencyInjection/Configuration.php | 6 +- .../TransportFactoryTest.php | 116 ++++-------------- pkg/simple-client/SimpleClient.php | 6 +- 4 files changed, 34 insertions(+), 100 deletions(-) diff --git a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php index 2deb06a1f..56151e956 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php +++ b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php @@ -12,11 +12,11 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $tb = new TreeBuilder('enqueue_async_event_dispatcher'); - - if (method_exists($tb, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('enqueue_async_event_dispatcher'); $rootNode = $tb->getRootNode(); } else { + $tb = new TreeBuilder(); $rootNode = $tb->root('enqueue_async_event_dispatcher'); } diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index 074ea8267..6257fa4f1 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -24,11 +24,11 @@ public function __construct(bool $debug) public function getConfigTreeBuilder(): TreeBuilder { - $tb = new TreeBuilder('enqueue'); - - if (method_exists($tb, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('enqueue'); $rootNode = $tb->getRootNode(); } else { + $tb = new TreeBuilder(); $rootNode = $tb->root('enqueue'); } diff --git a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php index 7b76eeffd..92d89dd88 100644 --- a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php @@ -11,6 +11,7 @@ use Interop\Queue\ConnectionFactory; use Interop\Queue\Context; use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Processor; @@ -37,13 +38,7 @@ public function testThrowIfEmptyNameGivenOnConstruction() public function testShouldAllowAddConfigurationAsStringDsn() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -64,13 +59,7 @@ public function testShouldAllowAddConfigurationAsStringDsn() */ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -86,13 +75,7 @@ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() public function testShouldSetNullTransportIfNullGiven() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -108,13 +91,7 @@ public function testShouldSetNullTransportIfNullGiven() public function testShouldSetNullTransportIfEmptyStringGiven() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -130,13 +107,7 @@ public function testShouldSetNullTransportIfEmptyStringGiven() public function testShouldSetNullTransportIfEmptyArrayGiven() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -152,13 +123,7 @@ public function testShouldSetNullTransportIfEmptyArrayGiven() public function testThrowIfEmptyDsnGiven() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -170,13 +135,7 @@ public function testThrowIfEmptyDsnGiven() public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -194,13 +153,7 @@ public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTime() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -218,13 +171,7 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTi public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSameTime() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -241,13 +188,7 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSame public function testShouldAllowSetFactoryClass() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -264,13 +205,7 @@ public function testShouldAllowSetFactoryClass() public function testShouldAllowSetFactoryService() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -287,13 +222,7 @@ public function testShouldAllowSetFactoryService() public function testShouldAllowSetConnectionFactoryClass() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -310,13 +239,7 @@ public function testShouldAllowSetConnectionFactoryClass() public function testThrowIfExtraOptionGiven() { - $tb = new TreeBuilder('foo'); - - if (method_exists($tb, 'getRootNode')) { - $rootNode = $tb->getRootNode(); - } else { - $rootNode = $tb->root('foo'); - } + $rootNode = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -529,4 +452,15 @@ public function testThrowIfBuildRpcClientCalledButContextServiceDoesNotExist() $this->expectExceptionMessage('The service "enqueue.transport.default.context" does not exist.'); $transport->buildRpcClient($container, []); } + + private function getRootNode(): NodeDefinition + { + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('foo'); + return $tb->getRootNode(); + } + + $tb = new TreeBuilder(); + return $tb->root('foo'); + } } diff --git a/pkg/simple-client/SimpleClient.php b/pkg/simple-client/SimpleClient.php index dd0eb7466..0e03da77d 100644 --- a/pkg/simple-client/SimpleClient.php +++ b/pkg/simple-client/SimpleClient.php @@ -306,11 +306,11 @@ public function build(array $configs): void private function createConfiguration(): NodeInterface { - $tb = new TreeBuilder('enqueue'); - - if (method_exists($tb, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('enqueue'); $rootNode = $tb->getRootNode(); } else { + $tb = new TreeBuilder(); $rootNode = $tb->root('enqueue'); } From 463725b301d2aba18bce3e49adb03b2e35dfd627 Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Fri, 14 Dec 2018 13:14:51 +0000 Subject: [PATCH 4/5] Fix wonky var return --- .../TransportFactoryTest.php | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php index 92d89dd88..68868716b 100644 --- a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php @@ -38,7 +38,7 @@ public function testThrowIfEmptyNameGivenOnConstruction() public function testShouldAllowAddConfigurationAsStringDsn() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -59,7 +59,7 @@ public function testShouldAllowAddConfigurationAsStringDsn() */ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -75,7 +75,7 @@ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() public function testShouldSetNullTransportIfNullGiven() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -91,7 +91,7 @@ public function testShouldSetNullTransportIfNullGiven() public function testShouldSetNullTransportIfEmptyStringGiven() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -107,7 +107,7 @@ public function testShouldSetNullTransportIfEmptyStringGiven() public function testShouldSetNullTransportIfEmptyArrayGiven() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -123,7 +123,7 @@ public function testShouldSetNullTransportIfEmptyArrayGiven() public function testThrowIfEmptyDsnGiven() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -135,7 +135,7 @@ public function testThrowIfEmptyDsnGiven() public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -153,7 +153,7 @@ public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTime() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -171,7 +171,7 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTi public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSameTime() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -188,7 +188,7 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSame public function testShouldAllowSetFactoryClass() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -205,7 +205,7 @@ public function testShouldAllowSetFactoryClass() public function testShouldAllowSetFactoryService() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -222,7 +222,7 @@ public function testShouldAllowSetFactoryService() public function testShouldAllowSetConnectionFactoryClass() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -239,7 +239,7 @@ public function testShouldAllowSetConnectionFactoryClass() public function testThrowIfExtraOptionGiven() { - $rootNode = $this->getRootNode(); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -453,14 +453,19 @@ public function testThrowIfBuildRpcClientCalledButContextServiceDoesNotExist() $transport->buildRpcClient($container, []); } - private function getRootNode(): NodeDefinition + /** + * @return [TreeBuilder, NodeDefinition] + */ + private function getRootNode(): array { if (method_exists(TreeBuilder::class, 'getRootNode')) { $tb = new TreeBuilder('foo'); - return $tb->getRootNode(); + + return [$tb, $tb->getRootNode()]; } $tb = new TreeBuilder(); - return $tb->root('foo'); + + return [$tb, $tb->root('foo')]; } } From 5c48b7c9a38ec666b3c3d7f320eed4cf07b2dca1 Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Fri, 14 Dec 2018 13:31:19 +0000 Subject: [PATCH 5/5] Exclude from STAN --- phpstan.neon | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 1a51a46e1..222a9fe95 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,4 +10,7 @@ parameters: - pkg/job-queue/Test/JobRunner.php - pkg/job-queue/Tests/Functional/app/AppKernel.php - pkg/rdkafka/RdKafkaConsumer.php - + - pkg/async-event-dispatcher/DependencyInjection/Configuration.php + - pkg/enqueue-bundle/DependencyInjection/Configuration.php + - pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php + - pkg/simple-client/SimpleClient.php