Skip to content

Commit

Permalink
that's not how check-updates works, instead return the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzsequence committed Apr 3, 2024
1 parent 259fe4b commit 6844831
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 9 additions & 4 deletions features/steps/given.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,20 @@ function($world) {
);

$steps->Given('/^the current WP version is not the latest$/', function ($world) {
// Fetch the latest WordPress version info from the WordPress.org API
$url = 'https://api.wordpress.org/core/version-check/1.7/';
$json = file_get_contents($url);
$data = json_decode($json, true);

// Extract the latest version number
$latestVersion = $data['offers'][0]['current'];

// Use wp-cli to get the currently installed WordPress version.
$currentVersion = $world->proc('wp core version')->run();

// Use wp-cli to get the latest WordPress version available.
$latestVersion = $world->proc('wp core check-update --field=version')->run();

// Normalize versions (remove new lines).
$currentVersion = trim($currentVersion->stdout);
$latestVersion = trim($latestVersion->stdout);
$latestVersion = trim($latestVersion);

// If there's no update available or the current version is the latest, throw an exception to skip the test.
if (empty($latestVersion) || $currentVersion === $latestVersion) {
Expand Down
1 change: 0 additions & 1 deletion features/steps/then.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function ( $world, $return_code ) {

$steps->Then( '/^(STDOUT|STDERR) should (be|contain|not contain):$/',
function ( $world, $stream, $action, PyStringNode $expected ) {

// Conditional handling of WP version check.
if (isset($world->isLatestWPVersion) && $world->isLatestWPVersion) {
return;
Expand Down

0 comments on commit 6844831

Please sign in to comment.