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 diff --git a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php index 9703e6284..56151e956 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php +++ b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php @@ -12,8 +12,13 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('enqueue_async_event_dispatcher'); + 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'); + } $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..6257fa4f1 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -24,8 +24,13 @@ public function __construct(bool $debug) public function getConfigTreeBuilder(): TreeBuilder { - $tb = new TreeBuilder(); - $rootNode = $tb->root('enqueue'); + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('enqueue'); + $rootNode = $tb->getRootNode(); + } else { + $tb = new TreeBuilder(); + $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 6cc02b697..68868716b 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,8 +38,7 @@ public function testThrowIfEmptyNameGivenOnConstruction() public function testShouldAllowAddConfigurationAsStringDsn() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -59,8 +59,7 @@ public function testShouldAllowAddConfigurationAsStringDsn() */ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -76,8 +75,7 @@ public function testShouldAllowAddConfigurationAsDsnWithoutSlashes() public function testShouldSetNullTransportIfNullGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -93,8 +91,7 @@ public function testShouldSetNullTransportIfNullGiven() public function testShouldSetNullTransportIfEmptyStringGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -110,8 +107,7 @@ public function testShouldSetNullTransportIfEmptyStringGiven() public function testShouldSetNullTransportIfEmptyArrayGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -127,8 +123,7 @@ public function testShouldSetNullTransportIfEmptyArrayGiven() public function testThrowIfEmptyDsnGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -140,8 +135,7 @@ public function testThrowIfEmptyDsnGiven() public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -159,8 +153,7 @@ public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime() public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTime() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); @@ -178,8 +171,7 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryClassAtTheSameTi public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSameTime() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -196,8 +188,7 @@ public function testThrowIfConnectionFactoryClassUsedWithFactoryServiceAtTheSame public function testShouldAllowSetFactoryClass() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -214,8 +205,7 @@ public function testShouldAllowSetFactoryClass() public function testShouldAllowSetFactoryService() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -232,8 +222,7 @@ public function testShouldAllowSetFactoryService() public function testShouldAllowSetConnectionFactoryClass() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -250,8 +239,7 @@ public function testShouldAllowSetConnectionFactoryClass() public function testThrowIfExtraOptionGiven() { - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + list($tb, $rootNode) = $this->getRootNode(); $rootNode->append(TransportFactory::getConfiguration()); $processor = new Processor(); @@ -464,4 +452,20 @@ public function testThrowIfBuildRpcClientCalledButContextServiceDoesNotExist() $this->expectExceptionMessage('The service "enqueue.transport.default.context" does not exist.'); $transport->buildRpcClient($container, []); } + + /** + * @return [TreeBuilder, NodeDefinition] + */ + private function getRootNode(): array + { + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('foo'); + + return [$tb, $tb->getRootNode()]; + } + + $tb = new TreeBuilder(); + + return [$tb, $tb->root('foo')]; + } } diff --git a/pkg/simple-client/SimpleClient.php b/pkg/simple-client/SimpleClient.php index 4e3d8e9d6..0e03da77d 100644 --- a/pkg/simple-client/SimpleClient.php +++ b/pkg/simple-client/SimpleClient.php @@ -306,8 +306,13 @@ public function build(array $configs): void private function createConfiguration(): NodeInterface { - $tb = new TreeBuilder(); - $rootNode = $tb->root('enqueue'); + if (method_exists(TreeBuilder::class, 'getRootNode')) { + $tb = new TreeBuilder('enqueue'); + $rootNode = $tb->getRootNode(); + } else { + $tb = new TreeBuilder(); + $rootNode = $tb->root('enqueue'); + } $rootNode ->beforeNormalization()