diff --git a/features/check.feature b/features/check.feature index 998e054..b88d834 100644 --- a/features/check.feature +++ b/features/check.feature @@ -185,3 +185,49 @@ Feature: Basic check usage And STDOUT should be a table containing rows: | name | status | | autoload-options-size | success | + + Scenario: Use --verbose flag to see check progress + Given a WP install + + When I run `wp doctor check autoload-options-size --verbose` + Then STDOUT should contain: + """ + Running check: autoload-options-size + """ + And STDOUT should contain: + """ + Status: + """ + + Scenario: Use --verbose flag with multiple checks + Given a WP install + + When I run `wp doctor check autoload-options-size core-update --verbose` + Then STDOUT should contain: + """ + Running check: autoload-options-size + """ + And STDOUT should contain: + """ + Running check: core-update + """ + + Scenario: Use --verbose flag with file checks + Given a WP install + And a wp-content/plugins/foo.php file: + """ + $args ) ); if ( empty( $checks ) ) { @@ -125,7 +135,7 @@ public function check( $args, $assoc_args ) { } $file_checks = array(); $progress = false; - if ( $all && 'table' === $assoc_args['format'] ) { + if ( $all && 'table' === $assoc_args['format'] && ! $verbose ) { $progress = Utils\make_progress_bar( 'Running checks', count( $checks ) ); } foreach ( $checks as $name => $check ) { @@ -133,12 +143,19 @@ public function check( $args, $assoc_args ) { if ( $when ) { WP_CLI::add_hook( $when, - static function () use ( $name, $check, &$completed, &$progress ) { + static function () use ( $name, $check, &$completed, &$progress, $verbose ) { + if ( $verbose ) { + WP_CLI::log( "Running check: {$name}" ); + } $check->run(); $completed[ $name ] = $check; if ( $progress ) { $progress->tick(); } + if ( $verbose ) { + $results = $check->get_results(); + WP_CLI::log( " Status: {$results['status']}" ); + } } ); } else { @@ -151,12 +168,20 @@ static function () use ( $name, $check, &$completed, &$progress ) { if ( ! empty( $file_checks ) ) { WP_CLI::add_hook( 'after_wp_config_load', - static function () use ( $file_checks, &$completed, &$progress ) { + static function () use ( $file_checks, &$completed, &$progress, $verbose ) { + if ( $verbose ) { + WP_CLI::log( 'Scanning filesystem for file checks...' ); + } try { $directory = new RecursiveDirectoryIterator( ABSPATH, RecursiveDirectoryIterator::SKIP_DOTS ); $iterator = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::CHILD_FIRST ); $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content'; + $file_count = 0; foreach ( $iterator as $file ) { + ++$file_count; + if ( $verbose && 0 === $file_count % self::VERBOSE_FILE_SCAN_INTERVAL ) { + WP_CLI::log( " Scanned {$file_count} files..." ); + } foreach ( $file_checks as $name => $check ) { $options = $check->get_options(); if ( ! empty( $options['only_wp_content'] ) @@ -174,15 +199,25 @@ static function () use ( $file_checks, &$completed, &$progress ) { $check->check_file( $file ); } } + if ( $verbose ) { + WP_CLI::log( " Total files scanned: {$file_count}" ); + } } catch ( Exception $e ) { WP_CLI::warning( $e->getMessage() ); } foreach ( $file_checks as $name => $check ) { + if ( $verbose ) { + WP_CLI::log( "Running check: {$name}" ); + } $check->run(); $completed[ $name ] = $check; if ( $progress ) { $progress->tick(); } + if ( $verbose ) { + $results = $check->get_results(); + WP_CLI::log( " Status: {$results['status']}" ); + } } } );