From 212e3a028b5b1d12a56fb93babfa101c415ab5d6 Mon Sep 17 00:00:00 2001 From: Loulier Guillaume Date: Wed, 3 Jun 2020 08:46:42 +0200 Subject: [PATCH 1/2] feat(issue_62): autoconfigure & autowire under progress --- .phpunit.result.cache | 1 + .travis.yml | 1 + composer.json | 5 +- phpunit.xml.dist | 21 ++++++++ src/Context/ContextArgumentResolver.php | 19 ++++++++ src/ServiceContainer/SymfonyExtension.php | 38 +++++++++++++++ tests/Context/ContextArgumentResolverTest.php | 21 ++++++++ .../ServiceContainer/ServiceContainerTest.php | 48 +++++++++++++++++++ 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 .phpunit.result.cache create mode 100644 phpunit.xml.dist create mode 100644 src/Context/ContextArgumentResolver.php create mode 100644 tests/Context/ContextArgumentResolverTest.php create mode 100644 tests/ServiceContainer/ServiceContainerTest.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..0a6b209 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":446:{a:2:{s:7:"defects";a:3:{s:7:"Warning";i:6;s:78:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCannotBeDone";i:4;s:75:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCanBeDone";i:5;}s:5:"times";a:3:{s:7:"Warning";d:0.005;s:78:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCannotBeDone";d:0.025;s:75:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCanBeDone";d:0.001;}}} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index b6bbfb2..9bbb8e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,3 +32,4 @@ script: - composer check - vendor/bin/behat -f progress --strict -vvv --no-interaction + - vendor/bin/phpunit tests diff --git a/composer.json b/composer.json index 204747f..418050f 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,13 @@ "friends-of-behat/mink-extension": "^2.2", "friends-of-behat/page-object-extension": "^0.3.1", "friends-of-behat/service-container-extension": "^1.0", - "vimeo/psalm": "3.10.1", + "phpunit/phpunit": "^8.5", "sylius-labs/coding-standard": "^3.0", "symfony/browser-kit": "^4.4|^5.0", "symfony/framework-bundle": "^4.4|^5.0", "symfony/process": "^4.4|^5.0", - "symfony/yaml": "^4.4|^5.0" + "symfony/yaml": "^4.4|^5.0", + "vimeo/psalm": "3.10.1" }, "suggest": { "friends-of-behat/mink": "^1.7", diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..c8150e9 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + + + + tests/ + + + diff --git a/src/Context/ContextArgumentResolver.php b/src/Context/ContextArgumentResolver.php new file mode 100644 index 0000000..0c62f97 --- /dev/null +++ b/src/Context/ContextArgumentResolver.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FriendsOfBehat\SymfonyExtension\Context; + +final class ContextArgumentResolver +{ + +} diff --git a/src/ServiceContainer/SymfonyExtension.php b/src/ServiceContainer/SymfonyExtension.php index e27a8e1..ebb2775 100644 --- a/src/ServiceContainer/SymfonyExtension.php +++ b/src/ServiceContainer/SymfonyExtension.php @@ -2,8 +2,18 @@ declare(strict_types=1); +/* + * This file is part of the SymfonyExtension package. + * + * (c) Kamil Kokot + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace FriendsOfBehat\SymfonyExtension\ServiceContainer; +use Behat\Behat\Context\Context; use Behat\Behat\Context\ServiceContainer\ContextExtension; use Behat\Mink\Session; use Behat\MinkExtension\ServiceContainer\MinkExtension; @@ -37,6 +47,11 @@ final class SymfonyExtension implements Extension */ public const DRIVER_KERNEL_ID = 'fob_symfony.driver_kernel'; + /** + * Used to auto tag every context injected in the container. + */ + private const CONTEXT_TAG = 'fob_symfony.context'; + /** @var bool */ private $minkExtensionFound = false; @@ -63,6 +78,8 @@ public function configure(ArrayNodeDefinition $builder): void ->scalarNode('class')->defaultNull()->end() ->scalarNode('environment')->defaultNull()->end() ->booleanNode('debug')->defaultNull()->end() + ->booleanNode('autoconfigure')->defaultFalse()->end() + ->booleanNode('step_autowiring')->defaultFalse()->end() ->end() ->end() ->end() @@ -87,6 +104,15 @@ public function load(ContainerBuilder $container, array $config): void $this->loadMinkDefaultSession($container); $this->loadMinkParameters($container); } + + if ($config['autoconfigure']) { + $this->handleAutoConfiguration($container); + } + + if ($config['step_autowiring']) { + $this->handleAutoWiring($container); + } + } public function process(ContainerBuilder $container): void @@ -266,4 +292,16 @@ private function autodiscoverBootstrap($bootstrap): ?string return is_string($bootstrap) ? $bootstrap : null; } + + private function handleAutoConfiguration(ContainerBuilder $container): void + { + $container->registerForAutoconfiguration(Context::class)->addTag(self::CONTEXT_TAG); + } + + private function handleAutoWiring(ContainerBuilder $container): void + { + foreach ($container->findTaggedServiceIds(self::CONTEXT_TAG) as $contextId => $tags) { + + } + } } diff --git a/tests/Context/ContextArgumentResolverTest.php b/tests/Context/ContextArgumentResolverTest.php new file mode 100644 index 0000000..efba008 --- /dev/null +++ b/tests/Context/ContextArgumentResolverTest.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Tests\Context; + +use PHPUnit\Framework\TestCase; + +final class ContextArgumentResolverTest extends TestCase +{ + +} diff --git a/tests/ServiceContainer/ServiceContainerTest.php b/tests/ServiceContainer/ServiceContainerTest.php new file mode 100644 index 0000000..de1a81e --- /dev/null +++ b/tests/ServiceContainer/ServiceContainerTest.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Tests\ServiceContainer; + +use Behat\Behat\Context\Context; +use FriendsOfBehat\SymfonyExtension\ServiceContainer\SymfonyExtension; +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +final class ServiceContainerTest extends TestCase +{ + public function testAutoConfigurationCannotBeDone(): void + { + $container = $this->createMock(ContainerBuilder::class); + $container->expects(self::never())->method('registerForAutoconfiguration'); + $container->expects(self::never())->method('findTaggedServiceIds'); + + $extension = new SymfonyExtension(); + $extension->load($container, [ + 'bootstrap' => null, + 'kernel' => [ + 'class' => 'Kernel', + 'path' => 'src/', + ], + 'autoconfigure' => false, + 'step_autowiring' => false, + ]); + } + + public function testAutoConfigurationCanBeDone(): void + { + } +} + +final class FooContext implements Context +{ +} From 2e1b7753a05698a9bfc71edf12995501b5ed1b3d Mon Sep 17 00:00:00 2001 From: Loulier Guillaume Date: Tue, 9 Jun 2020 18:10:20 +0200 Subject: [PATCH 2/2] fix(core): fix on first reviews --- .gitignore | 1 + .phpunit.result.cache | 1 - phpunit.xml.dist | 2 +- ...riendsOfBehatSymfonyExtensionExtension.php | 11 +++++-- src/ServiceContainer/SymfonyExtension.php | 31 ++----------------- 5 files changed, 12 insertions(+), 34 deletions(-) delete mode 100644 .phpunit.result.cache diff --git a/.gitignore b/.gitignore index 5eb3730..f6bf610 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /composer.lock /behat.yml +.phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 0a6b209..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":446:{a:2:{s:7:"defects";a:3:{s:7:"Warning";i:6;s:78:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCannotBeDone";i:4;s:75:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCanBeDone";i:5;}s:5:"times";a:3:{s:7:"Warning";d:0.005;s:78:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCannotBeDone";d:0.025;s:75:"Tests\ServiceContainer\ServiceContainerTest::testAutoConfigurationCanBeDone";d:0.001;}}} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c8150e9..f5fe040 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ provideMinkIntegration($container); $this->registerBehatContainer($container); $this->registerDriverBehatContainer($container); - $container->registerForAutoconfiguration(Context::class)->addTag('fob.context'); + $container->registerForAutoconfiguration(Context::class)->addTag(self::CONTEXT_TAG); } public function process(ContainerBuilder $container): void { $this->provideBrowserKitIntegration($container); - foreach ($container->findTaggedServiceIds('fob.context') as $serviceId => $attributes) { + foreach ($container->findTaggedServiceIds(self::CONTEXT_TAG) as $serviceId => $attributes) { $serviceDefinition = $container->findDefinition($serviceId); $serviceDefinition->setPublic(true); - $serviceDefinition->clearTag('fob.context'); + $serviceDefinition->clearTag(self::CONTEXT_TAG); } } diff --git a/src/ServiceContainer/SymfonyExtension.php b/src/ServiceContainer/SymfonyExtension.php index ebb2775..88cb37a 100644 --- a/src/ServiceContainer/SymfonyExtension.php +++ b/src/ServiceContainer/SymfonyExtension.php @@ -13,7 +13,6 @@ namespace FriendsOfBehat\SymfonyExtension\ServiceContainer; -use Behat\Behat\Context\Context; use Behat\Behat\Context\ServiceContainer\ContextExtension; use Behat\Mink\Session; use Behat\MinkExtension\ServiceContainer\MinkExtension; @@ -47,11 +46,6 @@ final class SymfonyExtension implements Extension */ public const DRIVER_KERNEL_ID = 'fob_symfony.driver_kernel'; - /** - * Used to auto tag every context injected in the container. - */ - private const CONTEXT_TAG = 'fob_symfony.context'; - /** @var bool */ private $minkExtensionFound = false; @@ -78,10 +72,10 @@ public function configure(ArrayNodeDefinition $builder): void ->scalarNode('class')->defaultNull()->end() ->scalarNode('environment')->defaultNull()->end() ->booleanNode('debug')->defaultNull()->end() - ->booleanNode('autoconfigure')->defaultFalse()->end() - ->booleanNode('step_autowiring')->defaultFalse()->end() ->end() ->end() + ->booleanNode('autoconfigure')->defaultFalse()->end() + ->booleanNode('step_autowiring')->defaultFalse()->end() ->end() ; } @@ -104,15 +98,6 @@ public function load(ContainerBuilder $container, array $config): void $this->loadMinkDefaultSession($container); $this->loadMinkParameters($container); } - - if ($config['autoconfigure']) { - $this->handleAutoConfiguration($container); - } - - if ($config['step_autowiring']) { - $this->handleAutoWiring($container); - } - } public function process(ContainerBuilder $container): void @@ -292,16 +277,4 @@ private function autodiscoverBootstrap($bootstrap): ?string return is_string($bootstrap) ? $bootstrap : null; } - - private function handleAutoConfiguration(ContainerBuilder $container): void - { - $container->registerForAutoconfiguration(Context::class)->addTag(self::CONTEXT_TAG); - } - - private function handleAutoWiring(ContainerBuilder $container): void - { - foreach ($container->findTaggedServiceIds(self::CONTEXT_TAG) as $contextId => $tags) { - - } - } }