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/.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..f5fe040 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + + + + tests/ + + + diff --git a/src/Bundle/DependencyInjection/FriendsOfBehatSymfonyExtensionExtension.php b/src/Bundle/DependencyInjection/FriendsOfBehatSymfonyExtensionExtension.php index 88cfeac..db5b27b 100644 --- a/src/Bundle/DependencyInjection/FriendsOfBehatSymfonyExtensionExtension.php +++ b/src/Bundle/DependencyInjection/FriendsOfBehatSymfonyExtensionExtension.php @@ -22,24 +22,29 @@ final class FriendsOfBehatSymfonyExtensionExtension extends Extension implements CompilerPassInterface { + /** + * Used to auto tag every context injected in the container. + */ + private const CONTEXT_TAG = 'fob.context'; + public function load(array $configs, ContainerBuilder $container): void { $this->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/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..88cb37a 100644 --- a/src/ServiceContainer/SymfonyExtension.php +++ b/src/ServiceContainer/SymfonyExtension.php @@ -2,6 +2,15 @@ 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\ServiceContainer\ContextExtension; @@ -65,6 +74,8 @@ public function configure(ArrayNodeDefinition $builder): void ->booleanNode('debug')->defaultNull()->end() ->end() ->end() + ->booleanNode('autoconfigure')->defaultFalse()->end() + ->booleanNode('step_autowiring')->defaultFalse()->end() ->end() ; } 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 +{ +}