Skip to content

Commit

Permalink
Merge pull request #7 from pamil/cross-container-extension
Browse files Browse the repository at this point in the history
Integrate with CrossContainerExtension
  • Loading branch information
pamil authored Nov 3, 2016
2 parents 1c5906c + 0681e81 commit f631646
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
"behat/mink": "^1.7",
"behat/mink-browserkit-driver": "^1.3",
"behat/mink-extension": "^2.2",
"friends-of-behat/cross-container-extension": "^0.1",
"friends-of-behat/test-context": "^0.3",
"symfony/framework-bundle": "^2.7|^3.0"
},
"suggest": {
"behat/mink-browserkit-driver": "^1.3"
"behat/mink-browserkit-driver": "^1.3",
"friends-of-behat/cross-container-extension": "^0.1"
},
"autoload": {
"psr-4": { "FriendsOfBehat\\SymfonyExtension\\": "src/" }
Expand Down
28 changes: 28 additions & 0 deletions features/not_crashing_behat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,31 @@ Feature: Not crashing Behat
And a feature file with passing scenario
When I run Behat
Then it should pass

Scenario: Not crashing Behat with CrossContainerExtension
Given a Behat configuration containing:
"""
default:
extensions:
FriendsOfBehat\SymfonyExtension:
kernel:
bootstrap: ~
FriendsOfBehat\CrossContainerExtension: ~
"""
And a file "app/AppKernel.php" containing:
"""
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles() { return []; }
public function registerContainerConfiguration(LoaderInterface $loader) {}
}
"""
And a feature file with passing scenario
When I run Behat
Then it should pass
41 changes: 41 additions & 0 deletions src/ServiceContainer/SymfonyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
use Behat\Testwork\ServiceContainer\Extension;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use FriendsOfBehat\CrossContainerExtension\CrossContainerProcessor;
use FriendsOfBehat\CrossContainerExtension\KernelBasedContainerAccessor;
use FriendsOfBehat\CrossContainerExtension\ServiceContainer\CrossContainerExtension;
use FriendsOfBehat\SymfonyExtension\Driver\Factory\SymfonyDriverFactory;
use FriendsOfBehat\SymfonyExtension\Listener\KernelRebooter;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -55,6 +59,11 @@ final class SymfonyExtension implements Extension
*/
const SHARED_KERNEL_CONTAINER_ID = 'sylius_symfony_extension.shared_kernel.container';

/**
* @var CrossContainerProcessor|null
*/
private $crossContainerProcessor;

/**
* {@inheritdoc}
*/
Expand All @@ -69,6 +78,7 @@ public function getConfigKey()
public function initialize(ExtensionManager $extensionManager)
{
$this->registerSymfonyDriverFactory($extensionManager);
$this->initializeCrossContainerProcessor($extensionManager);
}

/**
Expand Down Expand Up @@ -104,6 +114,7 @@ public function load(ContainerBuilder $container, array $config)
$this->loadSharedKernelContainer($container);

$this->loadKernelRebooter($container);
$this->declareSymfonyContainers($container);
}

/**
Expand Down Expand Up @@ -185,6 +196,36 @@ private function loadKernelRebooter(ContainerBuilder $container)
$container->setDefinition(self::KERNEL_ID . '.rebooter', $definition);
}

/**
* @param ContainerBuilder $container
*/
private function declareSymfonyContainers(ContainerBuilder $container)
{
if (null !== $this->crossContainerProcessor) {
$this->crossContainerProcessor->addContainerAccessor(
'symfony',
new KernelBasedContainerAccessor($container->get(self::KERNEL_ID))
);

$this->crossContainerProcessor->addContainerAccessor(
'symfony',
new KernelBasedContainerAccessor($container->get(self::SHARED_KERNEL_ID))
);
}
}

/**
* @param ExtensionManager $extensionManager
*/
private function initializeCrossContainerProcessor(ExtensionManager $extensionManager)
{
/** @var CrossContainerExtension $extension */
$extension = $extensionManager->getExtension('fob_cross_container');
if (null !== $extension) {
$this->crossContainerProcessor = $extension->getCrossContainerProcessor();
}
}

/**
* @param ExtensionManager $extensionManager
*/
Expand Down

0 comments on commit f631646

Please sign in to comment.