Skip to content

Commit

Permalink
FIX Don't bootstrap when running behat -h or behat --help (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Feb 12, 2024
1 parent 1c4463f commit f16cb65
Showing 1 changed file with 25 additions and 5 deletions.
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']);
}
}

0 comments on commit f16cb65

Please sign in to comment.