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

Drupal finder exception causes error - Cannot locate Drupal on a standalone behat installation. #658

Open
MiroslavRusev opened this issue Jan 25, 2024 · 2 comments

Comments

@MiroslavRusev
Copy link

throw new \RuntimeException('Cannot locate Drupal');

I am currently using the region map of the Drupal Extension in a behat, which is installed without Drupal. The behat.yml config looks like:
Drupal\DrupalExtension:
region_map:
region1: ".clss"

I've tried adding blackbox:~ but it doesn't do anything and I think it's because of Line 86 in the same file (DrupalExtension.php). The problem is the exception is thrown before reading the configuration, so there is no way to start Behat with DrupalExtension if no drupal is installed on the same machine. This problem was not present in previous versions as there was no usage of DrupalFinder() in that file.
https://github.com/jhedstrom/drupalextension/blob/4.2/src/Drupal/DrupalExtension/ServiceContainer/DrupalExtension.php#L64

@MiroslavRusev
Copy link
Author

v 4.2.0 -
image

v5 -
image

@MiroslavRusev
Copy link
Author

MiroslavRusev commented Jan 30, 2024

I can't open a PR, but I think this should be the fix:

public function load(ContainerBuilder $container, array $config)
  {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
        $loader->load('services.yml');
        $container->setParameter('drupal.drupal.default_driver', $config['default_driver']);

        $this->loadParameters($container, $config);
        if (!isset($config['blackbox'])) {
            // Workaround a bug in BrowserKitDriver that wrongly considers as text
            // of the page, pieces of texts inside the <head> section.
            // @see https://github.com/minkphp/MinkBrowserKitDriver/issues/153
            // @see https://www.drupal.org/project/drupal/issues/3175718
            $drupalFinder = new DrupalFinder();
            if (!$drupalFinder->locateRoot(getcwd())) {
                throw new \RuntimeException('Cannot locate Drupal');
            }
            $drupalRoot = $drupalFinder->getDrupalRoot();
            require_once($drupalRoot . '/core/tests/Drupal/Tests/DocumentElement.php');
            class_alias('\Drupal\Tests\DocumentElement', '\Behat\Mink\Element\DocumentElement', true);
        }

        // Setup any drivers if requested.
        $this->loadBlackbox($loader, $config);
        $this->loadDrupal($loader, $container, $config);
        $this->loadDrush($loader, $container, $config);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant