Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Registering custom context initializers with behat 3
custom_extension.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');
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
You can’t perform that action at this time.