#55632 closed defect (bug) (fixed)
WordPress database error when running PHPUnit tests
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.0 | Priority: | normal |
| Severity: | normal | Version: | 6.0 |
| Component: | Upgrade/Install | Keywords: | needs-testing has-patch |
| Focuses: | Cc: |
Description
When running PHPUnit tests, a database error is reported before the first test is run
WordPress database error Table 'wordpress_develop_tests.wptests_posts' doesn't exist for query
SELECT wptests_posts.ID
FROM wptests_posts
WHERE 1=1 AND (
0 = 1
) AND wptests_posts.post_type = 'wp_global_styles' AND ((wptests_posts.post_status = 'publish'))
GROUP BY wptests_posts.ID
ORDER BY wptests_posts.post_date DESC
<div id="error"><p class="wpdberror"><strong>WordPress database error:</strong> [Table 'wordpress_develop_tests.wptests_posts' doesn't exist]<br /><code>
SELECT wptests_posts.ID
FROM wptests_posts
LIMIT 0, 1
WHERE 1=1 AND (
made by require_once('wp-settings.php'), do_action('wp_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, {closure}, {closure}, WP_Theme_JSON_Resolver::get_merged_data, WP_Theme_JSON_Resolver::get_user_data, WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles, wp_get_recent_posts, get_posts, WP_Query->query, WP_Query->get_posts
0 = 1
) AND wptests_posts.post_type = 'wp_global_styles' AND ((wptests_posts.post_status = 'publish'))
GROUP BY wptests_posts.ID
ORDER BY wptests_posts.post_date DESC
LIMIT 0, 1
</code></p></div>
See for example: https://github.com/WordPress/wordpress-develop/runs/6195555843?check_suite_focus=true
Attachments (1)
Change History (11)
#3
@
4 years ago
- Component changed from General to Build/Test Tools
- Keywords needs-patch needs-testing added
Hi @Chouby, I'll check this out when I'm back at my PC later today.
#4
@
4 years ago
cc @hellofromTonya
Thanks for reporting this @Chouby, as always your efforts testing beta and RC releases is greatly appreciated.
#5
follow-up:
↓ 7
@
4 years ago
- Keywords has-patch added; needs-patch removed
I was able to reproduce this locally.
- Open test database in your favourite MySQL interface
- Drop all of the tables
- Run
phpunitand observe the error described above.
55632.diff fixes the problem by assuming there are no webfonts to enqueue during installation and bypassing the check of WP_Theme_JSON_Resolver. An alternative might be to move $fn_register_webfonts to run early on the wp_enqueue_scripts hook.
The fuller solution is probably at a lower level in which FSE themes check whether WP is installed before attempting to access the FSE posts.
This ticket was mentioned in PR #2638 on WordPress/wordpress-develop by peterwilsoncc.
4 years ago
#6
https://core.trac.wordpress.org/ticket/55632
Just making sure the tests pass.
#7
in reply to:
↑ 5
;
follow-up:
↓ 8
@
4 years ago
Replying to peterwilsoncc:
An alternative might be to move
$fn_register_webfontsto run early on thewp_enqueue_scriptshook.
Just noting that this option also works in my testing. Could that be the preferred approach here? Is there a use case for registering webfonts earlier, like currently on the wp_loaded hook?
#8
in reply to:
↑ 7
@
4 years ago
- Component changed from Build/Test Tools to Upgrade/Install
I realised overnight the same error would occur during installation. As it's a user facing component, I've moved the ticket to that.
Replying to SergeyBiryukov:
Just noting that this option also works in my testing.
Thanks for the logic check, I've updated the linked pull request to use wp_enqueue_scripts, 9. Technically the priority isn't needed as the actions run in order of registration but I figured I'd make it clear what was happening.
Is there a use case for registering webfonts earlier, like currently on the
wp_loadedhook?
Not that I am aware of for theme.json.
Testing notes
In all cases, you will need to check out the branch of the linked pull request. This can be done by running npm run grunt patch:https://github.com/WordPress/wordpress-develop/pull/2638 in a wordpress-develop environment.
Unit tests
- Drop test database tables in test database
- Run
phpunit - Check for reported database table does not exist errors
WP CLI Installation
In your local environments root directory:
- Run
wp db reset - Run
wp core install --title=WP-DEV --admin_user=admin --admin_password=password --admin_email=admin@example.com --url=wp-dev.local(replace the URL as appropriate) - Check for reported database table does not exist errors
Manual Installation
- In your local environments root directory run
wp db reset. Alternatively drop all tables via a MySQL interface - Visit your local environment in the browser and follow the installation steps
- Check for reported database table does not exist errors
#9
@
4 years ago
- Owner set to peterwilsoncc
- Resolution set to fixed
- Status changed from new to closed
In 53306:
This is the first commit firing the error: https://github.com/WordPress/wordpress-develop/commit/02414638ce37bb4a58fad2491151fb2fcf4a4e73