Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DI-test-autowiring #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 9, 2019
Merged

DI-test-autowiring #2

merged 6 commits into from
Apr 9, 2019

Conversation

gilles-g
Copy link
Member

@gilles-g gilles-g commented Apr 9, 2019

No description provided.

@gilles-g
Copy link
Member Author

gilles-g commented Apr 9, 2019

@chalasr If you have some times, did you know how to fix that test? 🤔
https://github.com/lexik/LexikCronFileGeneratorBundle/blob/master/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php

Help to debug, trace:

1) Lexik\Bundle\CronFileGeneratorBundle\Tests\DependencyInjection\LexikCronFileGeneratorExtensionTest::testLoadEmptyConfiguration
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "twig.loader".

@chalasr
Copy link

chalasr commented Apr 9, 2019

@Spike31 here you go:

diff --git a/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php b/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
index 10929db..05b4d5a 100644
--- a/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
+++ b/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
@@ -11,9 +11,11 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
 use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
 use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
 use Symfony\Bundle\TwigBundle\TwigBundle;
+use Symfony\Component\Config\Loader\LoaderInterface;
 use Symfony\Component\DependencyInjection\Compiler\PassConfig;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
+use Symfony\Component\HttpKernel\Kernel;
 
 class LexikCronFileGeneratorExtensionTest extends TestCase
 {
@@ -60,8 +62,7 @@ class LexikCronFileGeneratorExtensionTest extends TestCase
             ->setAutowired(true);
 
         $this->compileContainer($container);
-dd($container->get('templating'));
-        $autowired = $container->get('autowired');
+        $this->assertInstanceOf(Autowired::class, $container->get('autowired'));
     }
 
     private function createContainer(array $configs = [])
@@ -82,6 +83,14 @@ dd($container->get('templating'));
             ],
         ]));
 
+        $container->set('kernel', new class ('test', false) extends Kernel {
+            public function registerBundles()
+            {
+            }
+            public function registerContainerConfiguration(LoaderInterface $loader)
+            {
+            }
+        });
         $container->registerExtension(new FrameworkExtension());
         $container->registerExtension(new TwigExtension());
         $container->registerExtension(new LexikCronFileGeneratorExtension());
@@ -96,8 +105,10 @@ dd($container->get('templating'));
     private function compileContainer(ContainerBuilder $container)
     {
         $container->addCompilerPass(new TemplatingPass(), PassConfig::TYPE_BEFORE_REMOVING);
-        $container->getCompilerPassConfig()->setOptimizationPasses([]);
         $container->getCompilerPassConfig()->setRemovingPasses([]);
+
+        (new TwigBundle())->build($container);
+
         $container->compile();
     }
 }

@chalasr
Copy link

chalasr commented Apr 9, 2019

FYI the integration of the Templating component in FrameworkBundle is deprecated in Symfony 4.3 symfony/symfony#21035 (i.e. framework.templating configuration + templating.* services are deprecated)

@gilles-g
Copy link
Member Author

gilles-g commented Apr 9, 2019

Thx for you help, I have try a lot of things but not that.. 🤔

If I use use Symfony\Component\Templating\EngineInterface is ok, right?

@chalasr
Copy link

chalasr commented Apr 9, 2019

Nope, using the interface itself is fine, but you're relying on the templating service which is provided by FrameworkBundle (that's what is deprecated) in https://github.com/lexik/LexikCronFileGeneratorBundle/blob/master/Resources/config/dump_file.xml#L13. The bundle should use Twig directly instead, don't hesitate to ping me

composer.json Outdated
@@ -13,9 +13,7 @@
"require": {
"php": "^7.0",
"symfony/console": "^3.4|^4.0",
"symfony/framework-bundle": "^3.4|^4.0",
"symfony/templating": "^3.4|^4.0",
"symfony/twig-bundle": "^3.4|^4.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

framework-bundle and twig-bundle should probably be kept (as they provide dependency-injection and http-kernel, required for a bundle)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's was too much 🗡️

@gilles-g
Copy link
Member Author

gilles-g commented Apr 9, 2019

@chalasr Green is the new red! Thx for you help ;)

@gilles-g gilles-g merged commit 4345e07 into master Apr 9, 2019
@gilles-g gilles-g deleted the DI-test-autowiring branch April 9, 2019 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.