Skip to content

Instantly share code, notes, and snippets.

@tooky
Last active Dec 16, 2016
Embed
What would you like to do?
<?php
use Shouty\Shouty;
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 ShoutyHelper
{
private $shouty;
public function getShouty()
{
if(!isset($this->shouty))
$this->shouty = new Shouty();
return $this->shouty;
}
public function clear() {
unset($this->shouty);
}
}
class ShoutyInitializer implements ContextInitializer
{
private $shoutyHelper;
public function __construct()
{
$this->shoutyHelper = new ShoutyHelper();
}
public function supportsContext(Context $context)
{
return true;
}
public function initializeContext(Context $context)
{
$context->setShoutyHelper($this->shoutyHelper);
}
}
class ShoutyExtension implements Extension
{
public function getConfigKey()
{
return 'shouty_initializer';
}
public function load(ContainerBuilder $container, array $config)
{
$definition = $container->register('shouty_initializer', 'ShoutyInitializer');
$definition->addTag(ContextExtension::INITIALIZER_TAG);
}
public function configure(ArrayNodeDefinition $builder) {}
public function initialize(ExtensionManager $extensionManager) {}
public function process(ContainerBuilder $container) {}
}
return new ShoutyExtension;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment