From 8bce6a2d658789a5106b0b35449e8808405d857b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 1 Sep 2017 17:13:03 +0800 Subject: [PATCH 1/6] patch to proper overwrite 'label_translator_strategy' from yml config with 'sonata_admin.admin_services.label_translator_strategy' --- .../AddDependencyCallsCompilerPass.php | 2 +- DependencyInjection/Configuration.php | 59 +++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index 89e65e387c..675df5bcfd 100644 --- a/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -279,7 +279,7 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at 'menu_factory' => 'knp_menu.factory', 'route_builder' => 'sonata.admin.route.path_info'. (($manager_type == 'doctrine_phpcr') ? '_slashes' : ''), - 'label_translator_strategy' => 'sonata.admin.label.strategy.native', + 'label_translator_strategy' => null !== $settings['label_translator_strategy'] ? $settings['label_translator_strategy'] : 'sonata.admin.label.strategy.native', ); $definition->addMethodCall('setManagerType', array($manager_type)); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 472dc97f5b..229da852e5 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -245,36 +245,35 @@ public function getConfigTreeBuilder() ->end() ->end() ->arrayNode('admin_services') - ->prototype('array') - ->children() - ->scalarNode('model_manager')->defaultNull()->end() - ->scalarNode('form_contractor')->defaultNull()->end() - ->scalarNode('show_builder')->defaultNull()->end() - ->scalarNode('list_builder')->defaultNull()->end() - ->scalarNode('datagrid_builder')->defaultNull()->end() - ->scalarNode('translator')->defaultNull()->end() - ->scalarNode('configuration_pool')->defaultNull()->end() - ->scalarNode('route_generator')->defaultNull()->end() - ->scalarNode('validator')->defaultNull()->end() - ->scalarNode('security_handler')->defaultNull()->end() - ->scalarNode('label')->defaultNull()->end() - ->scalarNode('menu_factory')->defaultNull()->end() - ->scalarNode('route_builder')->defaultNull()->end() - ->scalarNode('label_translator_strategy')->defaultNull()->end() - ->scalarNode('pager_type')->defaultNull()->end() - ->arrayNode('templates') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('form') - ->prototype('scalar')->end() - ->end() - ->arrayNode('filter') - ->prototype('scalar')->end() - ->end() - ->arrayNode('view') - ->useAttributeAsKey('id') - ->prototype('scalar')->end() - ->end() + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model_manager')->defaultNull()->end() + ->scalarNode('form_contractor')->defaultNull()->end() + ->scalarNode('show_builder')->defaultNull()->end() + ->scalarNode('list_builder')->defaultNull()->end() + ->scalarNode('datagrid_builder')->defaultNull()->end() + ->scalarNode('translator')->defaultNull()->end() + ->scalarNode('configuration_pool')->defaultNull()->end() + ->scalarNode('route_generator')->defaultNull()->end() + ->scalarNode('validator')->defaultNull()->end() + ->scalarNode('security_handler')->defaultNull()->end() + ->scalarNode('label')->defaultNull()->end() + ->scalarNode('menu_factory')->defaultNull()->end() + ->scalarNode('route_builder')->defaultNull()->end() + ->scalarNode('label_translator_strategy')->defaultNull()->end() + ->scalarNode('pager_type')->defaultNull()->end() + ->arrayNode('templates') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('form') + ->prototype('scalar')->end() + ->end() + ->arrayNode('filter') + ->prototype('scalar')->end() + ->end() + ->arrayNode('view') + ->useAttributeAsKey('id') + ->prototype('scalar')->end() ->end() ->end() ->end() From 3609edc2a7776283a356a678a964906e3be009de Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 10 Sep 2017 23:06:59 +0800 Subject: [PATCH 2/6] test that if we overwrite label_translation_strategy the service is available in a service pool --- .../AddDependencyCallsCompilerPassTest.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index b5bfe10dee..bad181fe86 100644 --- a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -715,4 +715,41 @@ private function getContainer() return $container; } + + /** + * By default label translation policy is 'sonata.admin.label.strategy.native' + */ + public function testLabelTranslationStrategyDefaultConfig() + { + $container = $this->getContainer(); + + $this->extension->load([], $container); + + $compilerPass = new AddDependencyCallsCompilerPass(); + $compilerPass->process($container); + + $container->compile(); + + $this->assertContains('sonata.admin.label.strategy.native', $container->getServiceIds()); + } + + /** + * Overwritten default label translation policy service should be available in a services pool + * + * @depends testLabelTranslationStrategyDefaultConfig + */ + public function testLabelTranslationStrategyOverwrittenConfig() + { + $a = ['sonata_admin' => ['admin_services' => ['label_translator_strategy' => 'sonata.admin.label.strategy.underscore' ]]]; + $container = $this->getContainer(); + + $this->extension->load($a, $container); + + $compilerPass = new AddDependencyCallsCompilerPass(); + $compilerPass->process($container); + + $container->compile(); + + $this->assertContains('sonata.admin.label.strategy.underscore', $container->getServiceIds()); + } } From 0393402ccd284ae68304af68f824aac6e09409d9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 10 Sep 2017 23:10:28 +0800 Subject: [PATCH 3/6] fixing StyleCi for the test --- .../Compiler/AddDependencyCallsCompilerPassTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index bad181fe86..302aaaa125 100644 --- a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -723,7 +723,7 @@ public function testLabelTranslationStrategyDefaultConfig() { $container = $this->getContainer(); - $this->extension->load([], $container); + $this->extension->load(array(), $container); $compilerPass = new AddDependencyCallsCompilerPass(); $compilerPass->process($container); @@ -740,7 +740,13 @@ public function testLabelTranslationStrategyDefaultConfig() */ public function testLabelTranslationStrategyOverwrittenConfig() { - $a = ['sonata_admin' => ['admin_services' => ['label_translator_strategy' => 'sonata.admin.label.strategy.underscore' ]]]; + $a = array( + 'sonata_admin' => array( + 'admin_services' => array( + 'label_translator_strategy' => 'sonata.admin.label.strategy.underscore' + ) + ) + ); $container = $this->getContainer(); $this->extension->load($a, $container); From 0a7f655de573f509348012375e2a15b8628bb93d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 10 Sep 2017 23:12:44 +0800 Subject: [PATCH 4/6] OMG, StyleCI wants a periods at the end of the sentence. --- .../Compiler/AddDependencyCallsCompilerPassTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index 302aaaa125..cb6a8d1551 100644 --- a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -717,7 +717,7 @@ private function getContainer() } /** - * By default label translation policy is 'sonata.admin.label.strategy.native' + * By default label translation policy is 'sonata.admin.label.strategy.native'. */ public function testLabelTranslationStrategyDefaultConfig() { @@ -734,7 +734,7 @@ public function testLabelTranslationStrategyDefaultConfig() } /** - * Overwritten default label translation policy service should be available in a services pool + * Overwritten default label translation policy service should be available in a services pool. * * @depends testLabelTranslationStrategyDefaultConfig */ From 8ac9ea3f29b71212704f09cabfea790901a9c163 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 10 Sep 2017 23:23:22 +0800 Subject: [PATCH 5/6] okay, follow recommendation of codacy/pr , change variable name --- .../Compiler/AddDependencyCallsCompilerPassTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index cb6a8d1551..5a479379a9 100644 --- a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -740,7 +740,7 @@ public function testLabelTranslationStrategyDefaultConfig() */ public function testLabelTranslationStrategyOverwrittenConfig() { - $a = array( + $config = array( 'sonata_admin' => array( 'admin_services' => array( 'label_translator_strategy' => 'sonata.admin.label.strategy.underscore' @@ -749,7 +749,7 @@ public function testLabelTranslationStrategyOverwrittenConfig() ); $container = $this->getContainer(); - $this->extension->load($a, $container); + $this->extension->load($config, $container); $compilerPass = new AddDependencyCallsCompilerPass(); $compilerPass->process($container); From e5a8a25073d71c7c1b86c4ecc44920a9c8aed5ee Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 11 Sep 2017 00:34:41 +0800 Subject: [PATCH 6/6] AddDependencyCallsCompilerPassTest relocate public methods above protected --- .../AddDependencyCallsCompilerPassTest.php | 87 ++++++++++--------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index 5a479379a9..e7f4fc812e 100644 --- a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -521,6 +521,50 @@ public function testProcessAbstractAdminServiceInServiceDefinition() $this->assertSame('extra_argument_2', $definition->getArgument(3)); } + + /** + * By default label translation policy is 'sonata.admin.label.strategy.native'. + */ + public function testLabelTranslationStrategyDefaultConfig() + { + $container = $this->getContainer(); + + $this->extension->load(array(), $container); + + $compilerPass = new AddDependencyCallsCompilerPass(); + $compilerPass->process($container); + + $container->compile(); + + $this->assertContains('sonata.admin.label.strategy.native', $container->getServiceIds()); + } + + /** + * Overwritten default label translation policy service should be available in a services pool. + * + * @depends testLabelTranslationStrategyDefaultConfig + */ + public function testLabelTranslationStrategyOverwrittenConfig() + { + $config = array( + 'sonata_admin' => array( + 'admin_services' => array( + 'label_translator_strategy' => 'sonata.admin.label.strategy.underscore' + ) + ) + ); + $container = $this->getContainer(); + + $this->extension->load($config, $container); + + $compilerPass = new AddDependencyCallsCompilerPass(); + $compilerPass->process($container); + + $container->compile(); + + $this->assertContains('sonata.admin.label.strategy.underscore', $container->getServiceIds()); + } + /** * @return array */ @@ -715,47 +759,4 @@ private function getContainer() return $container; } - - /** - * By default label translation policy is 'sonata.admin.label.strategy.native'. - */ - public function testLabelTranslationStrategyDefaultConfig() - { - $container = $this->getContainer(); - - $this->extension->load(array(), $container); - - $compilerPass = new AddDependencyCallsCompilerPass(); - $compilerPass->process($container); - - $container->compile(); - - $this->assertContains('sonata.admin.label.strategy.native', $container->getServiceIds()); - } - - /** - * Overwritten default label translation policy service should be available in a services pool. - * - * @depends testLabelTranslationStrategyDefaultConfig - */ - public function testLabelTranslationStrategyOverwrittenConfig() - { - $config = array( - 'sonata_admin' => array( - 'admin_services' => array( - 'label_translator_strategy' => 'sonata.admin.label.strategy.underscore' - ) - ) - ); - $container = $this->getContainer(); - - $this->extension->load($config, $container); - - $compilerPass = new AddDependencyCallsCompilerPass(); - $compilerPass->process($container); - - $container->compile(); - - $this->assertContains('sonata.admin.label.strategy.underscore', $container->getServiceIds()); - } }