Created
March 31, 2014 09:22
-
-
Save everzet/9888598 to your computer and use it in GitHub Desktop.
Registering custom context initializers with behat 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: | |
extensions: | |
custom_extension.php: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Behat\Testwork\ServiceContainer\ExtensionManager; | |
use Behat\Testwork\ServiceContainer\Extension; | |
use Behat\Behat\Context\ServiceContainer\ContextExtension; | |
use Behat\Behat\Context\Initializer\ContextInitializer; | |
use Behat\Behat\Context\Context; | |
class CustomInitializer implements ContextInitializer | |
{ | |
public function supportsContext(Context $context) | |
{ | |
return true; | |
} | |
public function initializeContext(Context $context) | |
{ | |
// do the stuff with the $context | |
} | |
} | |
class CustomExtension implements Extension | |
{ | |
public function getConfigKey() | |
{ | |
return 'custom_extension'; | |
} | |
public function load(ContainerBuilder $container, array $config) | |
{ | |
$definition = $container->register('custom_initializer', 'CustomInitializer'); | |
$definition->addTag(ContextExtension::INITIALIZER_TAG); | |
} | |
public function configure(ArrayNodeDefinition $builder) {} | |
public function initialize(ExtensionManager $extensionManager) {} | |
public function process(ContainerBuilder $container) {} | |
} | |
return new CustomExtension; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment