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

FIX Don't bootstrap when running behat -h or behat --help #262

Merged
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
30 changes: 25 additions & 5 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
use RuntimeException;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

Expand All @@ -42,7 +43,6 @@ class Extension implements ExtensionInterface
*/
const SILVERSTRIPE_ID = 'silverstripe_extension';


/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -78,8 +78,10 @@ public function initialize(ExtensionManager $extensionManager)
public function load(ContainerBuilder $container, array $config)
{
// Load yml config
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader->load('silverstripe.yml');
if ($this->getShouldBootstrap($container)) {
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader->load('silverstripe.yml');
}

// Add CLI substitutions
$this->loadSuiteLocator($container);
Expand All @@ -105,8 +107,10 @@ public function load(ContainerBuilder $container, array $config)
*/
public function process(ContainerBuilder $container)
{
$corePass = new Compiler\CoreInitializationPass();
$corePass->process($container);
if ($this->getShouldBootstrap($container)) {
$corePass = new Compiler\CoreInitializationPass();
$corePass->process($container);
}
}

public function configure(ArrayNodeDefinition $builder)
Expand Down Expand Up @@ -203,4 +207,20 @@ protected function loadCallHandlers(ContainerBuilder $container, $errorReporting
$definition->addTag(CallExtension::CALL_HANDLER_TAG, ['priority' => 50]);
$container->setDefinition(CallExtension::CALL_HANDLER_TAG . '.runtime', $definition);
}

/**
* Check whether the extension should bootstrap or not.
* The extension should always bootstrap unless the `-h` or `--help` option is passed.
*/
private function getShouldBootstrap(ContainerBuilder $container): bool
{
if (!$container->has('cli.input')) {
// If the input isn't there for some bizarre reason, just assume we should bootstrap.
return true;
}

/** @var ArgvInput $input */
$input = $container->get('cli.input');
return !$input->hasParameterOption(['--help', '-h']);
}
}
Loading