Skip to content
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

Context autowiring | autoconfiguration #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/composer.lock

/behat.yml
.phpunit.result.cache
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ script:
- composer check

- vendor/bin/behat -f progress --strict -vvv --no-interaction
- vendor/bin/phpunit tests
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
bootstrap="vendor/autoload.php"
verbose="true">

<testsuites>
<testsuite name="SymfonyExtension Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/Context/ContextArgumentResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyExtension package.
*
* (c) Kamil Kokot <[email protected]>
*
* 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
{

}
11 changes: 11 additions & 0 deletions src/ServiceContainer/SymfonyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the SymfonyExtension package.
*
* (c) Kamil Kokot <[email protected]>
*
* 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;
Expand Down Expand Up @@ -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()
;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Context/ContextArgumentResolverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyExtension package.
*
* (c) Kamil Kokot <[email protected]>
*
* 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
{

}
48 changes: 48 additions & 0 deletions tests/ServiceContainer/ServiceContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyExtension package.
*
* (c) Kamil Kokot <[email protected]>
*
* 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
{
}