mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Merge pull request #55 from runcommand/51-fix-error-notice
Fix error notice when `SAVEQUERIES` is already defined
This commit is contained in:
commit
dee9217170
2 changed files with 38 additions and 3 deletions
30
features/profile.feature
Normal file
30
features/profile.feature
Normal file
|
@ -0,0 +1,30 @@
|
|||
Feature: Basic profile usage
|
||||
|
||||
Scenario: Profiler loads a summary table
|
||||
Given a WP install
|
||||
|
||||
When I run `wp profile --fields=stage`
|
||||
Then STDOUT should be a table containing rows:
|
||||
| stage |
|
||||
| bootstrap |
|
||||
| main_query |
|
||||
| template |
|
||||
|
||||
Scenario: Error when SAVEQUERIES is defined to false
|
||||
Given an empty directory
|
||||
And WP files
|
||||
And a database
|
||||
And a extra-php file:
|
||||
"""
|
||||
define( 'SAVEQUERIES', false );
|
||||
"""
|
||||
And I run `wp core config {CORE_CONFIG_SETTINGS} --extra-php < extra-php`
|
||||
|
||||
When I run `wp core install --url='https://localhost' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
|
||||
Then the return code should be 0
|
||||
|
||||
When I try `wp profile`
|
||||
Then STDERR should be:
|
||||
"""
|
||||
Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php
|
||||
"""
|
|
@ -61,9 +61,14 @@ class Command {
|
|||
WP_CLI::set_url( home_url( '/' ) );
|
||||
});
|
||||
}
|
||||
if ( ! defined( 'SAVEQUERIES' ) ) {
|
||||
define( 'SAVEQUERIES', true );
|
||||
}
|
||||
WP_CLI::add_hook( 'after_wp_config_load', function() {
|
||||
if ( defined( 'SAVEQUERIES' ) && ! SAVEQUERIES ) {
|
||||
WP_CLI::error( "'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php" );
|
||||
}
|
||||
if ( ! defined( 'SAVEQUERIES' ) ) {
|
||||
define( 'SAVEQUERIES', true );
|
||||
}
|
||||
});
|
||||
WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) );
|
||||
WP_CLI::add_wp_hook( 'pre_http_request', array( $this, 'wp_request_begin' ) );
|
||||
WP_CLI::add_wp_hook( 'http_api_debug', array( $this, 'wp_request_end' ) );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue