#57071 closed defect (bug) (invalid)
PHPUnit tests are broken
Reported by: | emanuelx | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
Hi, I'm using the test suite for testing the functionalities for my theme.
I've adapted your install.sh scripts in a single container, and it's working fine until version 6.0.
My tests configuration:
PHP version: 8.0.2
<?php ENV WP_TESTS_DIR=/app/wordpress/tests ENV WP_CORE_DIR=/usr/src/wordpress/ define( 'ABSPATH', getenv_docker('WP_CORE_DIR', '') );
Version <=6.0
The behaviour is:
- Install.php file - https://github.com/WordPress/wordpress-develop/blob/6.1/tests/phpunit/includes/install.php#L43
- on this line the require_once will duplicate the forward slash.
code line: require_once ABSPATH . '/wp-includes/class-wpdb.php';
Translated line: require_once '/usr/src/wordpress//wp-includes/class-wpdb.php'
- Mock-mailer file - https://github.com/WordPress/wordpress-develop/blob/6.1/tests/phpunit/includes/mock-mailer.php#L2
on this line we have a missing slash.
code line: require_once ABSPATH . 'wp-includes/PHPMailer/PHPMailer.php';
Translated line: require_once '/usr/src/wordpress/wp-includes/PHPMailer/PHPMailer.php';
On the first case, we have a duplicated forward slash, but this is necessary because the includes of phpMailer inside mock-mailer.php file.
but this works fine, without any issue.
Version 6.1
The version 6.1 of tests, the issue with duplicated forward slash will break the code, I don't know why on version <=6.0 it's working fine, and on version 6.1 the error is fired.
I've analysed the code, and this is issue with duplicated slash is present on the code for several versions. So, something was introduced on this version 6.1 to trigger the error with require_once.
Error ABSPATH with forward slash: /usr/src/wordpress/
<?php [11-Nov-2022 10:03:02 UTC] PHP Warning: require_once(/usr/src/wordpress//wp-includes/class-wpdb.php): Failed to open stream: No such file or directory in /app/wordpress/tests/includes/install.php on line 43 [11-Nov-2022 10:03:02 UTC] PHP Fatal error: Uncaught Error: Failed opening required '/usr/src/wordpress//wp-includes/class-wpdb.php' (include_path='.:/usr/local/lib/php') in /app/wordpress/tests/includes/install.php:43 Stack trace: #0 {main} thrown in /app/wordpress/tests/includes/install.php on line 43
Error ABSPATH without forward slash: /usr/src/wordpress
<?php [11-Nov-2022 10:05:45 UTC] PHP Warning: require_once(/usr/src/wordpresswp-includes/PHPMailer/PHPMailer.php): Failed to open stream: No such file or directory in /app/wordpress/tests/includes/mock-mailer.php on line 2 PHPUnit 9.5.26 by Sebastian Bergmann and contributors. Error in bootstrap script: Error: Failed opening required '/usr/src/wordpresswp-includes/PHPMailer/PHPMailer.php' (include_path='.:/usr/local/lib/php') #0 /app/wordpress/tests/includes/bootstrap.php(250): require_once() #1 /theme/tests/bootstrap.php(66): require('/app/wordpress/...') #2 /theme/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once('/theme/tests/bo...') #3 /theme/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load('/theme/tests/bo...') #4 /theme/vendor/phpunit/phpunit/src/TextUI/Command.php(565): PHPUnit\Util\FileLoader::checkAndLoad('./tests/bootstr...') #5 /theme/vendor/phpunit/phpunit/src/TextUI/Command.php(345): PHPUnit\TextUI\Command->handleBootstrap('./tests/bootstr...') #6 /theme/vendor/phpunit/phpunit/src/TextUI/Command.php(112): PHPUnit\TextUI\Command->handleArguments(Array) #7 /theme/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run(Array, true) #8 /theme/vendor/phpunit/phpunit/phpunit(98): PHPUnit\TextUI\Command::main() #9 /theme/vendor/bin/phpunit(123): include('/theme/vendor/p...') #10 {main} Script phpunit -c phpunit-no-coverage.xml.dev handling the phpunit event returned with error code 1
Change History (7)
#1
@
2 years ago
- Component changed from General to Build/Test Tools
- Description modified (diff)
- Keywords has-dev-note removed
#2
in reply to:
↑ description
@
2 years ago
#3
follow-up:
↓ 4
@
2 years ago
Hey @SergeyBiryukov, I've found the issue. For some reason my docker image doesn't updated the wordpress version, I'm still on 6.0.3.
I've updated my wordpress installation to 6.1, and worked again, But let me ask you, Why wordpress have some paths with double forward slash?
#4
in reply to:
↑ 3
@
2 years ago
Replying to emanuelx:
I've found the issue. For some reason my docker image doesn't updated the wordpress version, I'm still on 6.0.3.
I've updated my wordpress installation to 6.1, and worked again
Great, thanks for the follow-up!
But let me ask you, Why wordpress have some paths with double forward slash?
I think it's just an oversight, though it should not affect anything in practice.
We should be able to remove the extra slash from these lines in phpunit/includes/install.php
:
require_once ABSPATH . '/wp-settings.php'; require_once ABSPATH . '/wp-admin/includes/upgrade.php'; require_once ABSPATH . '/wp-includes/class-wpdb.php';
Searching for ABSPATH . '/
, it appears to also be present in some other core and test files:
src/wp-admin/includes/class-wp-site-health.php src/wp-admin/includes/class-wp-site-health-auto-updates.php src/wp-admin/includes/file.php tests/phpunit/includes/bootstrap.php tests/phpunit/includes/install.php tests/phpunit/tests/customize/widgets.php tests/phpunit/tests/feed/wpSimplePieFile.php tests/phpunit/tests/pluggable/signatures.php tests/phpunit/tests/pluggable/wpMail.php tests/phpunit/tests/pomo/po.php tests/phpunit/tests/post.php tests/phpunit/tests/widgets.php
Would you be interested in opening a new ticket to correct that?
#5
@
2 years ago
- Keywords needs-testing-info removed
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
- Version 6.1 deleted
There's also a file with ABSPATH . "/
.
I have created #57074 with a patch.
Nice find, @emanuelx! As there's nothing left to do in this ticket and as the reported behavior turned out to not be a problem in WP Core, I'll resolve this ticket as invalid
which is just the term used here for such cases.
#6
@
2 years ago
Thank you @TobiasBg, btw let me share with you my repository with my Dockerfile for tests, I did this because it's easier to run on a pipeline and it's ready for any theme/plugin.
https://github.com/emanuellopes/wordpress-tests
@SergeyBiryukov, Tobias already created them.
Hi there, welcome to WordPress Trac! Thanks for the report.
Replying to emanuelx:
Just to clarify,
ABSPATH
does need the trailing slash:So I don't think defining it without the slash would work.
Looking at the error:
I think the double forward slash is not the issue here, it rather has to do with the
wpdb
class file being renamed fromwp-db.php
toclass-wpdb.php
in 6.1, see #56268.Could you confirm that the file exists in
/usr/src/wordpress/
? Is that directory also updated to WordPress 6.1?