From 9d5d2cd36729e589ae18612f73944be62b0918f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 2 Oct 2025 14:24:13 +0200 Subject: [PATCH] fix: Simulate upgrade failure from code changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/Core/Command/App/UpdateTest.php | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/Core/Command/App/UpdateTest.php b/tests/Core/Command/App/UpdateTest.php index f095d2590ba..41aca65ae53 100644 --- a/tests/Core/Command/App/UpdateTest.php +++ b/tests/Core/Command/App/UpdateTest.php @@ -94,4 +94,61 @@ class UpdateTest extends TestCase { $output ); } + + public function testAppUpdateWithNewMethod(): void { + // First create new apps path + $apps_dirname = \sha1(\random_bytes(4)); + $new_apps_path = \sys_get_temp_dir() . '/' . $apps_dirname; + // Create an app within that path + mkdir($new_apps_path . '/test_app/lib', recursive:true); + file_put_contents( + $new_apps_path . '/test_app/lib/MyClass.php', + ' $new_apps_path, + // 'url' => '/apptest', + 'writable' => false, + ]; + + // Load the class as if as the app had been booted + require_once($new_apps_path . '/test_app/lib/MyClass.php'); + $object = new \OCA\FakeApp\MyClass('oldParam'); + + // Now, let’s update the app + $this->inputInterface->expects(self::once()) + ->method('getArgument') + ->with('app-id') + ->willReturn('test_app'); + $this->inputInterface->expects(self::any()) + ->method('getOption') + ->willReturnMap([ + ['allow-unstable', false], + ['showonly', false], + ]); + + $this->installer->expects(self::once()) + ->method('isUpdateAvailable') + ->willReturn('2.0.0'); + $this->installer->expects(self::once()) + ->method('updateAppstoreApp') + ->willReturnCallback( + function (string $appid, bool $allowUnstable) use ($new_apps_path): bool { + file_put_contents( + $new_apps_path . '/test_app/lib/MyClass.php', + 'assertEquals(0, self::invokePrivate($this->command, 'execute', [$this->inputInterface, $this->outputInterface])); + } }