mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 10:40:40 -04:00
fix: Simulate upgrade failure from code changes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
62d0b4e9a3
commit
9d5d2cd367
1 changed files with 57 additions and 0 deletions
|
|
@ -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, 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',
|
||||
'<?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]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue