Skip to content

Commit

Permalink
Merge pull request #253 from ernilambar/250-check-update-format
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Mar 14, 2024
2 parents b4aa439 + 5b50f5a commit 5774d7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
34 changes: 34 additions & 0 deletions features/core-check-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,37 @@ Feature: Check for more recent versions
"""
1
"""

Scenario: Check output of check update in different formats (no updates available)
Given a WP install
And a setup.php file:
"""
<?php
global $wp_version;
$obj = new stdClass;
$obj->updates = [];
$obj->last_checked = strtotime( '1 January 2099' );
$obj->version_checked = $wp_version;
$obj->translations = [];
set_site_transient( 'update_core', $obj );
"""
And I run `wp eval-file setup.php`

When I run `wp core check-update`
Then STDOUT should be:
"""
Success: WordPress is at the latest version.
"""

When I run `wp core check-update --format=json`
Then STDOUT should be:
"""
[]
"""

When I run `wp core check-update --format=yaml`
Then STDOUT should be:
"""
---
"""
6 changes: 4 additions & 2 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,18 @@ class Core_Command extends WP_CLI_Command {
* @subcommand check-update
*/
public function check_update( $_, $assoc_args ) {
$format = Utils\get_flag_value( $assoc_args, 'format', 'table' );

$updates = $this->get_updates( $assoc_args );
if ( $updates ) {

if ( $updates || 'table' !== $format ) {
$updates = array_reverse( $updates );
$formatter = new Formatter(
$assoc_args,
[ 'version', 'update_type', 'package_url' ]
);
$formatter->display_items( $updates );
} elseif ( empty( $assoc_args['format'] ) || 'table' === $assoc_args['format'] ) {
} else {
WP_CLI::success( 'WordPress is at the latest version.' );
}
}
Expand Down

0 comments on commit 5774d7d

Please sign in to comment.