From 73d3a90c0bdac76e61ee47befc9c66a43a7f18da Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 9 Nov 2025 13:11:17 +0000 Subject: [PATCH] test fixes Signed-off-by: Andy Miller --- .../Grav/Console/Gpm/SelfupgradeCommand.php | 6 +++--- .../Grav/Console/Gpm/PreflightCommandTest.php | 2 +- .../Console/Gpm/SelfupgradeCommandTest.php | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index e53c62836..81abb1712 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -404,7 +404,7 @@ class SelfupgradeCommand extends GpmCommand $isMajorMinorUpgrade = $preflight['is_major_minor_upgrade'] ?? false; // Fall back to calculating it if not provided (for backwards compatibility) - if (!isset($preflight['is_major_minor_upgrade'])) { + if (!isset($preflight['is_major_minor_upgrade']) && $this->upgrader) { $local = $this->upgrader->getLocalVersion(); $remote = $this->upgrader->getRemoteVersion(); $localParts = explode('.', $local); @@ -418,8 +418,8 @@ class SelfupgradeCommand extends GpmCommand $isMajorMinorUpgrade = ($localMajor !== $remoteMajor) || ($localMinor !== $remoteMinor); } - $local = $this->upgrader->getLocalVersion(); - $remote = $this->upgrader->getRemoteVersion(); + $local = $this->upgrader ? $this->upgrader->getLocalVersion() : 'unknown'; + $remote = $this->upgrader ? $this->upgrader->getRemoteVersion() : 'unknown'; $io->newLine(); $io->writeln('The following packages need updating before Grav upgrade:'); diff --git a/tests/unit/Grav/Console/Gpm/PreflightCommandTest.php b/tests/unit/Grav/Console/Gpm/PreflightCommandTest.php index 33045275d..e8f70d7c0 100644 --- a/tests/unit/Grav/Console/Gpm/PreflightCommandTest.php +++ b/tests/unit/Grav/Console/Gpm/PreflightCommandTest.php @@ -106,7 +106,7 @@ class StubSafeUpgradeService extends SafeUpgradeService parent::__construct([]); } - public function preflight(): array + public function preflight(?string $targetVersion = null): array { return $this->report; } diff --git a/tests/unit/Grav/Console/Gpm/SelfupgradeCommandTest.php b/tests/unit/Grav/Console/Gpm/SelfupgradeCommandTest.php index 6f87e1a3c..c2577da56 100644 --- a/tests/unit/Grav/Console/Gpm/SelfupgradeCommandTest.php +++ b/tests/unit/Grav/Console/Gpm/SelfupgradeCommandTest.php @@ -18,7 +18,8 @@ class SelfupgradeCommandTest extends \PHPUnit\Framework\TestCase $result = $command->runHandle([ 'plugins_pending' => [], 'psr_log_conflicts' => [], - 'warnings' => [] + 'warnings' => [], + 'is_major_minor_upgrade' => false ]); self::assertTrue($result); @@ -34,7 +35,8 @@ class SelfupgradeCommandTest extends \PHPUnit\Framework\TestCase $result = $command->runHandle([ 'plugins_pending' => ['foo' => ['type' => 'plugin', 'current' => '1', 'available' => '2']], 'psr_log_conflicts' => ['bar' => ['requires' => '^1.0']], - 'warnings' => ['pending'] + 'warnings' => ['pending'], + 'is_major_minor_upgrade' => true ]); self::assertFalse($result); @@ -51,7 +53,8 @@ class SelfupgradeCommandTest extends \PHPUnit\Framework\TestCase $result = $command->runHandle([ 'plugins_pending' => ['foo' => ['type' => 'plugin', 'current' => '1', 'available' => '2']], 'psr_log_conflicts' => [], - 'warnings' => [] + 'warnings' => [], + 'is_major_minor_upgrade' => true ]); self::assertFalse($result); @@ -67,7 +70,8 @@ class SelfupgradeCommandTest extends \PHPUnit\Framework\TestCase $result = $command->runHandle([ 'plugins_pending' => [], 'psr_log_conflicts' => ['foo' => ['requires' => '^1.0']], - 'warnings' => [] + 'warnings' => [], + 'is_major_minor_upgrade' => false ]); self::assertFalse($result); @@ -93,7 +97,8 @@ class SelfupgradeCommandTest extends \PHPUnit\Framework\TestCase $result = $command->runHandle([ 'plugins_pending' => [], 'psr_log_conflicts' => ['foo' => ['requires' => '^1.0']], - 'warnings' => [] + 'warnings' => [], + 'is_major_minor_upgrade' => false ]); self::assertTrue($result); @@ -110,7 +115,8 @@ class SelfupgradeCommandTest extends \PHPUnit\Framework\TestCase $result = $command->runHandle([ 'plugins_pending' => [], 'psr_log_conflicts' => ['foo' => ['requires' => '^1.0']], - 'warnings' => [] + 'warnings' => [], + 'is_major_minor_upgrade' => false ]); self::assertTrue($result);