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

This commit is contained in:
Guy Sartorelli 2024-02-09 14:30:52 +13:00
parent 1c4463f878
commit 829953dba9
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A

View File

@ -16,6 +16,7 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
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;
@ -42,7 +43,6 @@ class Extension implements ExtensionInterface
*/
const SILVERSTRIPE_ID = 'silverstripe_extension';
/**
* {@inheritDoc}
*/
@ -78,8 +78,10 @@ class Extension implements ExtensionInterface
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);
@ -105,8 +107,10 @@ class Extension implements ExtensionInterface
*/
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)
@ -203,4 +207,20 @@ class Extension implements ExtensionInterface
$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']);
}
}