fix: Simulate upgrade failure from code changes

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2025-10-02 14:24:13 +02:00
parent 62d0b4e9a3
commit 9d5d2cd367
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A

View file

@ -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',
'<?php namespace OCA\FakeApp; class MyClass { public function __construct(private string $oldParam) {} }'
);
// Add the app path
\OC::$APPSROOTS[] = [
'path' => $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, lets 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',
'<?php namespace OCA\FakeApp; class MyClass { public function __construct() {} }'
);
file_put_contents(
$new_apps_path . '/test_app/lib/MyMigration.php',
'<?php require_once __DIR__."/MyClass.php"; $object = new \OCA\FakeApp\MyClass(); // no param needed now'
);
require_once $new_apps_path . '/test_app/lib/MyMigration.php';
return true;
}
);
$this->assertEquals(0, self::invokePrivate($this->command, 'execute', [$this->inputInterface, $this->outputInterface]));
}
}