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

Setup behat tests to use the drupal router #219

Merged
merged 1 commit into from
Jun 23, 2023
Merged

Conversation

agentrickard
Copy link
Contributor

We just ran into this on DHS, which has some content aliased to foo-bar.htm which, it turns out, the local PHP server will not render when running

    nohup php -S ${CIRCLE_PROJECT_REPONAME}.local:8000 -t $(pwd)/${DRUPAL_ROOT}/ > /tmp/artifacts/phpd.log 2>&1 &
    vendor/bin/phing behat

After a few hours of debugging, I accidentally found that Drupal core already solved this with .ht.router.php which says:

/**
 * @file
 * Router script for the built-in PHP web server.
 *
 * The built-in web server should only be used for development and testing as it
 * has a number of limitations that makes running Drupal on it highly insecure
 * and somewhat limited.
 *
 * Note that:
 * - The server is single-threaded, any requests made during the execution of
 *   the main request will hang until the main request has been completed.
 * - The web server does not enforce any of the settings in .htaccess in
 *   particular a remote user will be able to download files that normally would
 *   be protected from direct access such as .module files.
 *
 * The router script is needed to work around a bug in PHP, see
 * https://bugs.php.net/bug.php?id=61286.
 *
 * Usage:
 * php -S localhost:8888 .ht.router.php
 *
 * @see http://php.net/manual/en/features.commandline.webserver.php
 */

Assuming this PR – https://github.com/palantirnet/wisdhs-public/pull/561 – ever passed, we should use this approach by default.

Note that a router file must be in the directory from which the server is started, so it is not compatible with our current usage of -t, else we get this error:

Warning: require(/home/circleci/wisdhs-public/index.php): Failed to open stream: No such file or directory in /home/circleci/wisdhs-public/docroot/.ht.router.php on line 65

Fatal error: Uncaught Error: Failed opening required '/home/circleci/wisdhs-public/index.php' (include_path='.:/usr/local/lib/php') in /home/circleci/wisdhs-public/docroot/.ht.router.php:65 Stack trace: #0 {main} thrown in /home/circleci/wisdhs-public/docroot/.ht.router.php on line 65

Testing steps

  • The automated tests should catch these changes, since we run behat tests by default in the-build.

Copy link
Contributor

@byrond byrond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now required for PHP to serve the *.js files while running @javascript Behat tests. I'm guessing a PHP update in the CircleCI Docker image must have changed this behavior, because the example JS was passing about a month ago without using this method.

@byrond byrond merged commit 4a7927e into develop Jun 23, 2023
@byrond byrond deleted the DEV-33-behat-php branch June 23, 2023 19:32
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

Successfully merging this pull request may close these issues.

2 participants