File tree 2 files changed +38
-2
lines changed
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,37 @@ Feature: Check for more recent versions
42
42
"""
43
43
1
44
44
"""
45
+
46
+ Scenario : Check output of check update in different formats (no updates available)
47
+ Given a WP install
48
+ And a setup.php file:
49
+ """
50
+ <?php
51
+ global $wp_version;
52
+
53
+ $obj = new stdClass;
54
+ $obj->updates = [];
55
+ $obj->last_checked = strtotime( '1 January 2099' );
56
+ $obj->version_checked = $wp_version;
57
+ $obj->translations = [];
58
+ set_site_transient( 'update_core', $obj );
59
+ """
60
+ And I run `wp eval-file setup.php`
61
+
62
+ When I run `wp core check-update`
63
+ Then STDOUT should be:
64
+ """
65
+ Success: WordPress is at the latest version.
66
+ """
67
+
68
+ When I run `wp core check-update --format=json`
69
+ Then STDOUT should be:
70
+ """
71
+ []
72
+ """
73
+
74
+ When I run `wp core check-update --format=yaml`
75
+ Then STDOUT should be:
76
+ """
77
+ ---
78
+ """
Original file line number Diff line number Diff line change @@ -77,16 +77,18 @@ class Core_Command extends WP_CLI_Command {
77
77
* @subcommand check-update
78
78
*/
79
79
public function check_update ( $ _ , $ assoc_args ) {
80
+ $ format = Utils \get_flag_value ( $ assoc_args , 'format ' , 'table ' );
80
81
81
82
$ updates = $ this ->get_updates ( $ assoc_args );
82
- if ( $ updates ) {
83
+
84
+ if ( $ updates || 'table ' !== $ format ) {
83
85
$ updates = array_reverse ( $ updates );
84
86
$ formatter = new Formatter (
85
87
$ assoc_args ,
86
88
[ 'version ' , 'update_type ' , 'package_url ' ]
87
89
);
88
90
$ formatter ->display_items ( $ updates );
89
- } elseif ( empty ( $ assoc_args [ ' format ' ] ) || ' table ' === $ assoc_args [ ' format ' ] ) {
91
+ } else {
90
92
WP_CLI ::success ( 'WordPress is at the latest version. ' );
91
93
}
92
94
}
You can’t perform that action at this time.
0 commit comments