Closed Genyus closed 7 months ago
Thanks @Genyus for taking the time to open an issue and complete the report. I will look into this next and either come back with a solution, or with questions to debug further.
Hi @Genyus,
I'm working on this and found some issues with Bedrock + default setup.
Did you choose yes
at this question during vendor/bin/codecept init wpbrowser
:
You can use a portable configuration based on PHP built-in server, Chromedriver and SQLite.
? Do you want to use this configuration? (y/n)
I've pushed what fixes I've applied so far on the v4-fix-716
branch, if you want you can test this out with:
composer require --dev lucatume/wp-browser:dev-v4-fix-716
I could run the Integration
suite successfully on that branch, but the EndToEnd
one fails the second test, the Admin login.
Can you run the EndToEnd
suite?
I'm using a setup similar to yours, with Lando to serve the Bedrock installation.
I tried to choose yes
during my early attempts, but I always got theAborted trying to redefine constant 'WP_SITEURL'.
error (that I see is now resolved in the fix branch), so had to select no
and then figure out the missing settings the hard way.
To eliminate any conflicts caused by existing project configuration, I created a completely fresh Bedrock + Lando install, installed WPBrowser from your new branch and tried again. After resolving a few local issues (e.g. not having Chrome installed), I was able to complete the setup and get the same results as you — Integration suite passed, EndToEnd failed.
With a working instance available, I compared my previous setup to see what was different, but couldn't find anything significant. I disabled all my tests and copied in the sample one, which worked fine, so I restored mine one at a time until I found the culprit — turns out that I hadn't converted it from a Codeception unit test to a WPBrowser test case. 🤦🏾♂️
With that resolved, I then had a dig around the E2E test suite to see if I could figure out why that wasn't working and eventually discovered the two-fold cause:
wp
directory. To fix, I created a new SERVER_ROOT_DIR
environment variable in tests/.env
, and modified the default one:
SERVER_ROOT_DIR=web
WORDPRESS_ROOT_DIR=${SERVER_ROOT_DIR}/wp
I then updated the BuiltInServerController
config in codeception.yml
to use this new value:
docroot: '%SERVER_ROOT_DIR%'
And finally, I modified the WPWebDriver
config in tests/EndToEndSuite.yml
to set the correct admin path for Bedrock:
adminPath: '/wp/wp-admin'
WP_HOME
environment variable is picked up from the main .env file and so requests to the test server were being redirected to the wrong URL. This meant I had to toggle the WP_HOME
value depending on whether I was accessing the regular or test site. After reviewing the relevant documentation, I decided to implement a slightly simpler check for whether the site is being loaded in a test environment inconfig/development.php
:
// Handle WPBrowser test configuration
if (getenv('WORDPRESS_URL')) {
// Reset default URLs
Config::define('WP_HOME', getenv('WORDPRESS_URL'));
Config::define('WP_SITEURL', Config::get('WP_HOME') . substr(env('WP_SITEURL'), strlen(env('WP_HOME')))); // Retain any appended path in WP_SITEURL, e.g. '/wp'
}
With these changes in place, all tests now pass successfully 🥳
@Genyus thanks for your feedback, I've built on it and, after a bit of iteration, removed the steps that would require modification of the config/environments/development.php
file.
Here is the result of the setup on a clean Bedrock installation
I will merge #718, and the transpiled #717, when all tests pass.
Thanks for implementing such a swift and comprehensive fix, much appreciated 🙏🏾
Environment OS: macOS 14.2 PHP version: 8.2 Installed Codeception version: 5.1.2 Installed wp-browser version: 4.1.6 WordPress version: 6.5 Local development environment: Lando WordPress structure and management: Bedrock
Did you use the
codecept init wpbrowser
command? YesDid you take a look at Codeception and wp-browser documentation? Yes
Codeception configuration file
Suite configuration file If you're encountering an issue with a specific suite, please provide its configuration file.
Test environment file
Describe the issue you're encountering This is my first time using WPBrowser and after a bit of trial and error due to my Bedrock setup, I've been able to get it running my initial tests. However, an error gets thrown during teardown where it attempts to clear the database, but the
$wpdb
object is null. I've configured the test database to use SQLite and the db appears to be correctly created and populated, but the teardown method is unable to access the corresponding object. My assumption was that it would pick up the database defined by the WPLoader module, but clearly I've misconfigured something, somewhere.I've included the output of a test run with
--debug
enabled below,Output
To Reproduce
codecept generate:wpunit Integration "Acme\User"
codecept run Integration