aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-07-29 10:14:29 -0100
committerMaxence Lange <maxence@artificial-owl.com>2024-07-29 12:44:52 -0100
commitad490c963bd88359a714fb2f1786aaf8c00ae17c (patch)
tree8dddff519102dbb73377fee762c91ff6792a1ad5
parent7c1ee524be784bf54d4c09d1310c182593d8b2f2 (diff)
downloadnextcloud-server-ad490c963bd88359a714fb2f1786aaf8c00ae17c.tar.gz
nextcloud-server-ad490c963bd88359a714fb2f1786aaf8c00ae17c.zip
feat(migration-attributes): tests
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--apps/testing/composer/composer/autoload_classmap.php1
-rw-r--r--apps/testing/composer/composer/autoload_static.php1
-rw-r--r--apps/testing/lib/Migration/Version30000Date20240102030405.php41
-rw-r--r--lib/private/Migration/MetadataManager.php9
-rw-r--r--lib/private/Updater/ReleaseMetadata.php3
-rw-r--r--lib/public/Migration/Attributes/AddColumn.php7
-rw-r--r--lib/public/Migration/Attributes/AddIndex.php5
-rw-r--r--lib/public/Migration/Attributes/ColumnMigrationAttribute.php4
-rw-r--r--lib/public/Migration/Attributes/ColumnType.php2
-rw-r--r--lib/public/Migration/Attributes/CreateTable.php2
-rw-r--r--lib/public/Migration/Attributes/DropColumn.php7
-rw-r--r--lib/public/Migration/Attributes/DropIndex.php6
-rw-r--r--lib/public/Migration/Attributes/DropTable.php2
-rw-r--r--lib/public/Migration/Attributes/GenericMigrationAttribute.php3
-rw-r--r--lib/public/Migration/Attributes/IndexMigrationAttribute.php4
-rw-r--r--lib/public/Migration/Attributes/IndexType.php2
-rw-r--r--lib/public/Migration/Attributes/MigrationAttribute.php7
-rw-r--r--lib/public/Migration/Attributes/ModifyColumn.php7
-rw-r--r--lib/public/Migration/Attributes/TableMigrationAttribute.php2
-rw-r--r--tests/lib/DB/MigrationsTest.php181
-rw-r--r--tests/lib/Updater/ReleaseMetadataTest.php209
21 files changed, 475 insertions, 30 deletions
diff --git a/apps/testing/composer/composer/autoload_classmap.php b/apps/testing/composer/composer/autoload_classmap.php
index 079f8877881..6dce2e26361 100644
--- a/apps/testing/composer/composer/autoload_classmap.php
+++ b/apps/testing/composer/composer/autoload_classmap.php
@@ -16,6 +16,7 @@ return array(
'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => $baseDir . '/../lib/Listener/RegisterDeclarativeSettingsListener.php',
'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => $baseDir . '/../lib/Listener/SetDeclarativeSettingsValueListener.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir . '/../lib/Locking/FakeDBLockingProvider.php',
+ 'OCA\\Testing\\Migration\\Version30000Date20240102030405' => $baseDir . '/../lib/Migration/Version30000Date20240102030405.php',
'OCA\\Testing\\Provider\\FakeText2ImageProvider' => $baseDir . '/../lib/Provider/FakeText2ImageProvider.php',
'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => $baseDir . '/../lib/Provider/FakeTextProcessingProvider.php',
'OCA\\Testing\\Provider\\FakeTextProcessingProviderSync' => $baseDir . '/../lib/Provider/FakeTextProcessingProviderSync.php',
diff --git a/apps/testing/composer/composer/autoload_static.php b/apps/testing/composer/composer/autoload_static.php
index 2332da70da9..3be58e04289 100644
--- a/apps/testing/composer/composer/autoload_static.php
+++ b/apps/testing/composer/composer/autoload_static.php
@@ -31,6 +31,7 @@ class ComposerStaticInitTesting
'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => __DIR__ . '/..' . '/../lib/Listener/RegisterDeclarativeSettingsListener.php',
'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => __DIR__ . '/..' . '/../lib/Listener/SetDeclarativeSettingsValueListener.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__ . '/..' . '/../lib/Locking/FakeDBLockingProvider.php',
+ 'OCA\\Testing\\Migration\\Version30000Date20240102030405' => __DIR__ . '/..' . '/../lib/Migration/Version30000Date20240102030405.php',
'OCA\\Testing\\Provider\\FakeText2ImageProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeText2ImageProvider.php',
'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeTextProcessingProvider.php',
'OCA\\Testing\\Provider\\FakeTextProcessingProviderSync' => __DIR__ . '/..' . '/../lib/Provider/FakeTextProcessingProviderSync.php',
diff --git a/apps/testing/lib/Migration/Version30000Date20240102030405.php b/apps/testing/lib/Migration/Version30000Date20240102030405.php
new file mode 100644
index 00000000000..bacb187cb37
--- /dev/null
+++ b/apps/testing/lib/Migration/Version30000Date20240102030405.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Testing\Migration;
+
+use Closure;
+use OCP\Migration\Attributes\AddColumn;
+use OCP\Migration\Attributes\AddIndex;
+use OCP\Migration\Attributes\ColumnType;
+use OCP\Migration\Attributes\CreateTable;
+use OCP\Migration\Attributes\DropColumn;
+use OCP\Migration\Attributes\DropIndex;
+use OCP\Migration\Attributes\DropTable;
+use OCP\Migration\Attributes\IndexType;
+use OCP\Migration\Attributes\ModifyColumn;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+#[DropTable('old_table')]
+#[CreateTable('new_table', description: 'Table is used to store things, but also to get more things', notes: ['this is a notice', 'and another one, if really needed'])]
+#[AddColumn('my_table')]
+#[AddColumn('my_table', 'another_field')]
+#[AddColumn('other_table', 'last_one', ColumnType::DATE)]
+#[AddIndex('my_table')]
+#[AddIndex('my_table', IndexType::PRIMARY)]
+#[DropColumn('other_table')]
+#[DropColumn('other_table', 'old_column', description: 'field is not used anymore and replaced by \'last_one\'')]
+#[DropIndex('other_table')]
+#[ModifyColumn('other_table')]
+#[ModifyColumn('other_table', 'this_field')]
+#[ModifyColumn('other_table', 'this_field', ColumnType::BIGINT)]
+class Version30000Date20240102030405 extends SimpleMigrationStep {
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+ return null;
+ }
+}
diff --git a/lib/private/Migration/MetadataManager.php b/lib/private/Migration/MetadataManager.php
index 2558d49f7f8..402252d6a46 100644
--- a/lib/private/Migration/MetadataManager.php
+++ b/lib/private/Migration/MetadataManager.php
@@ -36,7 +36,7 @@ class MetadataManager {
*
* @param string $appId
*
- * @return array
+ * @return array<string, MigrationAttribute[]>
* @since 30.0.0
*/
public function extractMigrationAttributes(string $appId): array {
@@ -48,7 +48,10 @@ class MetadataManager {
$class = new ReflectionClass($ms->createInstance($version));
$attributes = $class->getAttributes();
foreach ($attributes as $attribute) {
- $metadata[$version][] = $attribute->newInstance();
+ $item = $attribute->newInstance();
+ if ($item instanceof MigrationAttribute) {
+ $metadata[$version][] = $item;
+ }
}
}
@@ -144,7 +147,7 @@ class MetadataManager {
}
try {
- $attribute = new $class();
+ $attribute = new $class($item['table'] ?? '');
return $attribute->import($item);
} catch (\Error) {
throw new AttributeException('cannot import Attribute');
diff --git a/lib/private/Updater/ReleaseMetadata.php b/lib/private/Updater/ReleaseMetadata.php
index 22d8c843412..665847037e7 100644
--- a/lib/private/Updater/ReleaseMetadata.php
+++ b/lib/private/Updater/ReleaseMetadata.php
@@ -64,8 +64,7 @@ class ReleaseMetadata {
try {
$response = $client->get($url, [
'timeout' => 10,
- 'connect_timeout' => 10,
- 'verify' => false,
+ 'connect_timeout' => 10
]);
} catch (Exception $e) {
throw new ReleaseMetadataException('could not reach metadata at ' . $url, previous: $e);
diff --git a/lib/public/Migration/Attributes/AddColumn.php b/lib/public/Migration/Attributes/AddColumn.php
index 14a43c26f99..8d16b9b6e8d 100644
--- a/lib/public/Migration/Attributes/AddColumn.php
+++ b/lib/public/Migration/Attributes/AddColumn.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on new column creation
+ *
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
@@ -21,9 +23,8 @@ class AddColumn extends ColumnMigrationAttribute {
*/
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')';
- $table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\'';
return empty($this->getName()) ?
- 'Addition of a new column' . $type . $table
- : 'Addition of column \'' . $this->getName() . '\'' . $type . $table;
+ 'Addition of a new column' . $type . ' to table \'' . $this->getTable() . '\''
+ : 'Addition of column \'' . $this->getName() . '\'' . $type . ' to table \'' . $this->getTable() . '\'';
}
}
diff --git a/lib/public/Migration/Attributes/AddIndex.php b/lib/public/Migration/Attributes/AddIndex.php
index 2a6f0628db1..ee22fe7f128 100644
--- a/lib/public/Migration/Attributes/AddIndex.php
+++ b/lib/public/Migration/Attributes/AddIndex.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on index creation
+ *
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
@@ -21,7 +23,6 @@ class AddIndex extends IndexMigrationAttribute {
*/
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')';
- $table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\'';
- return 'Addition of a new index' . $type . $table;
+ return 'Addition of a new index' . $type . ' to table \'' . $this->getTable() . '\'';
}
}
diff --git a/lib/public/Migration/Attributes/ColumnMigrationAttribute.php b/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
index dab636a3aaa..b750932a257 100644
--- a/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
@@ -11,11 +11,13 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
/**
+ * generic class related to migration attribute about column changes
+ *
* @since 30.0.0
*/
class ColumnMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
- string $table = '',
+ string $table,
private string $name = '',
private ?ColumnType $type = null,
string $description = '',
diff --git a/lib/public/Migration/Attributes/ColumnType.php b/lib/public/Migration/Attributes/ColumnType.php
index 058b74f6516..23445e822b6 100644
--- a/lib/public/Migration/Attributes/ColumnType.php
+++ b/lib/public/Migration/Attributes/ColumnType.php
@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace OCP\Migration\Attributes;
/**
- * enum FieldType based on OCP\DB\Types
+ * enum ColumnType based on OCP\DB\Types
*
* @see \OCP\DB\Types
* @since 30.0.0
diff --git a/lib/public/Migration/Attributes/CreateTable.php b/lib/public/Migration/Attributes/CreateTable.php
index 8aac8cf247e..df0418fa4bc 100644
--- a/lib/public/Migration/Attributes/CreateTable.php
+++ b/lib/public/Migration/Attributes/CreateTable.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on table creation
+ *
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
diff --git a/lib/public/Migration/Attributes/DropColumn.php b/lib/public/Migration/Attributes/DropColumn.php
index 0bb3efb1917..1de0ba58489 100644
--- a/lib/public/Migration/Attributes/DropColumn.php
+++ b/lib/public/Migration/Attributes/DropColumn.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on column drop
+ *
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
@@ -20,9 +22,8 @@ class DropColumn extends ColumnMigrationAttribute {
* @since 30.0.0
*/
public function definition(): string {
- $table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\'';
return empty($this->getName()) ?
- 'Deletion of a column' . $table
- : 'Deletion of column \'' . $this->getName() . '\'' . $table;
+ 'Deletion of a column from table \'' . $this->getTable() . '\''
+ : 'Deletion of column \'' . $this->getName() . '\' from table \'' . $this->getTable() . '\'';
}
}
diff --git a/lib/public/Migration/Attributes/DropIndex.php b/lib/public/Migration/Attributes/DropIndex.php
index 0e72908ac35..2702cbed9a7 100644
--- a/lib/public/Migration/Attributes/DropIndex.php
+++ b/lib/public/Migration/Attributes/DropIndex.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on index drop
+ *
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
@@ -20,8 +22,6 @@ class DropIndex extends IndexMigrationAttribute {
* @since 30.0.0
*/
public function definition(): string {
- return empty($this->getTable()) ?
- 'Deletion of an index'
- : 'Deletion of an index from table \'' . $this->getTable() . '\'';
+ return 'Deletion of an index from table \'' . $this->getTable() . '\'';
}
}
diff --git a/lib/public/Migration/Attributes/DropTable.php b/lib/public/Migration/Attributes/DropTable.php
index 5741af14108..e90e4804a3c 100644
--- a/lib/public/Migration/Attributes/DropTable.php
+++ b/lib/public/Migration/Attributes/DropTable.php
@@ -11,7 +11,9 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on table drop
*
+ * @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class DropTable extends TableMigrationAttribute {
diff --git a/lib/public/Migration/Attributes/GenericMigrationAttribute.php b/lib/public/Migration/Attributes/GenericMigrationAttribute.php
index 1f40d77d1f1..d0c39a4a1a9 100644
--- a/lib/public/Migration/Attributes/GenericMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/GenericMigrationAttribute.php
@@ -11,6 +11,9 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
/**
+ * generic entry, used to replace migration attribute not yet known in current version
+ * but used in a future release
+ *
* @since 30.0.0
*/
class GenericMigrationAttribute extends MigrationAttribute implements JsonSerializable {
diff --git a/lib/public/Migration/Attributes/IndexMigrationAttribute.php b/lib/public/Migration/Attributes/IndexMigrationAttribute.php
index 33c5177c8ac..0d6e946890e 100644
--- a/lib/public/Migration/Attributes/IndexMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/IndexMigrationAttribute.php
@@ -11,11 +11,13 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
/**
+ * generic class related to migration attribute about index changes
+ *
* @since 30.0.0
*/
class IndexMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
- string $table = '',
+ string $table,
private ?IndexType $type = null,
string $description = '',
array $notes = [],
diff --git a/lib/public/Migration/Attributes/IndexType.php b/lib/public/Migration/Attributes/IndexType.php
index b957aebafa7..45c88d81041 100644
--- a/lib/public/Migration/Attributes/IndexType.php
+++ b/lib/public/Migration/Attributes/IndexType.php
@@ -9,6 +9,8 @@ declare(strict_types=1);
namespace OCP\Migration\Attributes;
/**
+ * type of index
+ *
* @since 30.0.0
*/
enum IndexType : string {
diff --git a/lib/public/Migration/Attributes/MigrationAttribute.php b/lib/public/Migration/Attributes/MigrationAttribute.php
index b9d698241d4..19b2ffb56ed 100644
--- a/lib/public/Migration/Attributes/MigrationAttribute.php
+++ b/lib/public/Migration/Attributes/MigrationAttribute.php
@@ -15,7 +15,7 @@ use JsonSerializable;
*/
class MigrationAttribute implements JsonSerializable {
public function __construct(
- private string $table = '',
+ private string $table,
private string $description = '',
private array $notes = [],
) {
@@ -93,8 +93,7 @@ class MigrationAttribute implements JsonSerializable {
* @since 30.0.0
*/
public function import(array $data): self {
- return $this->setTable($data['table'] ?? '')
- ->setDescription($data['description'] ?? '')
+ return $this->setDescription($data['description'] ?? '')
->setNotes($data['notes'] ?? []);
}
@@ -107,7 +106,7 @@ class MigrationAttribute implements JsonSerializable {
'class' => get_class($this),
'table' => $this->getTable(),
'description' => $this->getDescription(),
- 'notes' => $this->getNotes(),
+ 'notes' => $this->getNotes()
];
}
}
diff --git a/lib/public/Migration/Attributes/ModifyColumn.php b/lib/public/Migration/Attributes/ModifyColumn.php
index 216a911d90f..ef7250ffb34 100644
--- a/lib/public/Migration/Attributes/ModifyColumn.php
+++ b/lib/public/Migration/Attributes/ModifyColumn.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use Attribute;
/**
+ * attribute on column modification
+ *
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
@@ -21,9 +23,8 @@ class ModifyColumn extends ColumnMigrationAttribute {
*/
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' to ' . $this->getType()->value;
- $table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\'';
return empty($this->getName()) ?
- 'Modification of a column' . $table . $type
- : 'Modification of column \'' . $this->getName() . '\'' . $table . $type;
+ 'Modification of a column from table \'' . $this->getTable() . '\'' . $type
+ : 'Modification of column \'' . $this->getName() . '\' from table \'' . $this->getTable() . '\'' . $type;
}
}
diff --git a/lib/public/Migration/Attributes/TableMigrationAttribute.php b/lib/public/Migration/Attributes/TableMigrationAttribute.php
index 571173b9ba1..f3ba406a4ab 100644
--- a/lib/public/Migration/Attributes/TableMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/TableMigrationAttribute.php
@@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
/**
+ * generic class related to migration attribute about table changes
+ *
* @since 30.0.0
*/
class TableMigrationAttribute extends MigrationAttribute implements JsonSerializable {
diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php
index 2bdd705ff5d..a088ca1baf0 100644
--- a/tests/lib/DB/MigrationsTest.php
+++ b/tests/lib/DB/MigrationsTest.php
@@ -19,8 +19,21 @@ use Doctrine\DBAL\Types\Type;
use OC\DB\Connection;
use OC\DB\MigrationService;
use OC\DB\SchemaWrapper;
+use OC\Migration\MetadataManager;
+use OCP\App\IAppManager;
use OCP\IDBConnection;
+use OCP\Migration\Attributes\AddColumn;
+use OCP\Migration\Attributes\AddIndex;
+use OCP\Migration\Attributes\ColumnType;
+use OCP\Migration\Attributes\CreateTable;
+use OCP\Migration\Attributes\DropColumn;
+use OCP\Migration\Attributes\DropIndex;
+use OCP\Migration\Attributes\DropTable;
+use OCP\Migration\Attributes\IndexType;
+use OCP\Migration\Attributes\ModifyColumn;
use OCP\Migration\IMigrationStep;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class MigrationsTest
@@ -28,10 +41,9 @@ use OCP\Migration\IMigrationStep;
* @package Test\DB
*/
class MigrationsTest extends \Test\TestCase {
- /** @var MigrationService | \PHPUnit\Framework\MockObject\MockObject */
- private $migrationService;
- /** @var \PHPUnit\Framework\MockObject\MockObject | IDBConnection $db */
- private $db;
+ private MigrationService|MockObject $migrationService;
+ private MockObject|IDBConnection $db;
+ private IAppManager $appManager;
protected function setUp(): void {
parent::setUp();
@@ -39,6 +51,8 @@ class MigrationsTest extends \Test\TestCase {
$this->db = $this->createMock(Connection::class);
$this->db->expects($this->any())->method('getPrefix')->willReturn('test_oc_');
$this->migrationService = new MigrationService('testing', $this->db);
+
+ $this->appManager = Server::get(IAppManager::class);
}
public function testGetters() {
@@ -755,4 +769,163 @@ class MigrationsTest extends \Test\TestCase {
self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
}
+
+
+ public function testExtractMigrationAttributes() {
+ $metadataManager = Server::get(MetadataManager::class);
+ $this->appManager->loadApp('testing');
+
+ $this->assertEquals($this->getMigrationMetadata(), json_decode(json_encode($metadataManager->extractMigrationAttributes('testing')), true));
+
+ $this->appManager->disableApp('testing');
+ }
+
+ public function testDeserializeMigrationMetadata() {
+ $metadataManager = Server::get(MetadataManager::class);
+ $this->assertEquals(
+ [
+ 'core' => [],
+ 'apps' => [
+ 'testing' => [
+ '30000Date20240102030405' => [
+ new DropTable('old_table'),
+ new CreateTable('new_table',
+ description: 'Table is used to store things, but also to get more things',
+ notes: ['this is a notice', 'and another one, if really needed']
+ ),
+ new AddColumn('my_table'),
+ new AddColumn('my_table', 'another_field'),
+ new AddColumn('other_table', 'last_one', ColumnType::DATE),
+ new AddIndex('my_table'),
+ new AddIndex('my_table', IndexType::PRIMARY),
+ new DropColumn('other_table'),
+ new DropColumn('other_table', 'old_column',
+ description: 'field is not used anymore and replaced by \'last_one\''
+ ),
+ new DropIndex('other_table'),
+ new ModifyColumn('other_table'),
+ new ModifyColumn('other_table', 'this_field'),
+ new ModifyColumn('other_table', 'this_field', ColumnType::BIGINT)
+ ]
+ ]
+ ]
+ ],
+ $metadataManager->getMigrationsAttributesFromReleaseMetadata(
+ [
+ 'core' => [],
+ 'apps' => ['testing' => $this->getMigrationMetadata()]
+ ]
+ )
+ );
+ }
+
+ private function getMigrationMetadata(): array {
+ return [
+ '30000Date20240102030405' => [
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropTable',
+ 'table' => 'old_table',
+ 'description' => '',
+ 'notes' => [],
+ 'columns' => []
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\CreateTable',
+ 'table' => 'new_table',
+ 'description' => 'Table is used to store things, but also to get more things',
+ 'notes' =>
+ [
+ 'this is a notice',
+ 'and another one, if really needed'
+ ],
+ 'columns' => []
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => '',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'another_field',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'last_one',
+ 'type' => 'date'
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddIndex',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddIndex',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'type' => 'primary'
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => '',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropColumn',
+ 'table' => 'other_table',
+ 'description' => 'field is not used anymore and replaced by \'last_one\'',
+ 'notes' => [],
+ 'name' => 'old_column',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropIndex',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => '',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'this_field',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'this_field',
+ 'type' => 'bigint'
+ ],
+ ]
+ ];
+ }
}
diff --git a/tests/lib/Updater/ReleaseMetadataTest.php b/tests/lib/Updater/ReleaseMetadataTest.php
new file mode 100644
index 00000000000..25fe3949152
--- /dev/null
+++ b/tests/lib/Updater/ReleaseMetadataTest.php
@@ -0,0 +1,209 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace Test\Updater;
+
+use OC\Updater\ReleaseMetadata;
+use OCP\Http\Client\IClient;
+use OCP\Http\Client\IClientService;
+use OCP\Http\Client\IResponse;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class ReleaseMetadataTest extends \Test\TestCase {
+ private IClientService| MockObject $clientService;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->clientService = $this->getMockBuilder(IClientService::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ public function testDownloadMetadata() {
+ $client = $this->createMock(IClient::class);
+ $response = $this->createMock(IResponse::class);
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->with()
+ ->willReturn($client);
+ $client->expects($this->once())
+ ->method('get')
+ ->willReturn($response);
+ $response->expects($this->once())
+ ->method('getBody')
+ ->with()
+ ->willReturn($this->resultRequest());
+
+
+ $releaseMetadata = new ReleaseMetadata($this->clientService);
+ $this->assertSame($this->resultRequestArray(), $releaseMetadata->downloadMetadata('ouila'));
+ }
+
+ /**
+ * @dataProvider getMetadataUrlProvider
+ *
+ * @param string $version
+ * @param string $url
+ */
+ public function testGetMetadata(string $version, string $url) {
+ $client = $this->createMock(IClient::class);
+ $response = $this->createMock(IResponse::class);
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->with()
+ ->willReturn($client);
+ $client->expects($this->once())
+ ->method('get')
+ ->with($url)
+ ->willReturn($response);
+
+ $response->expects($this->once())
+ ->method('getBody')
+ ->with()
+ ->willReturn('{}');
+
+ $releaseMetadata = new ReleaseMetadata($this->clientService);
+ $releaseMetadata->getMetadata($version);
+ }
+
+ /**
+ * @return array
+ */
+ public function getMetadataUrlProvider(): array {
+ return [
+ [
+ '30.0.0',
+ 'https://download.nextcloud.com/server/releases/nextcloud-30.0.0.metadata'
+ ],
+ [
+ '30.0.0-beta1',
+ 'https://download.nextcloud.com/server/prereleases/nextcloud-30.0.0-beta1.metadata'
+ ],
+ [
+ '30',
+ 'https://download.nextcloud.com/server/releases/latest-30.metadata'
+ ]
+ ];
+ }
+
+ private function resultRequest(): string {
+ return json_encode($this->resultRequestArray());
+ }
+
+ private function resultRequestArray(): array {
+ return [
+ 'migrations' => [
+ 'core' => [],
+ 'apps' => [
+ 'testing' => [
+ '30000Date20240102030405' => [
+ 'class' => 'OCP\\Migration\\Attributes\\DropTable',
+ 'table' => 'old_table',
+ 'description' => '',
+ 'notes' => [],
+ 'columns' => []
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\CreateTable',
+ 'table' => 'new_table',
+ 'description' => 'Table is used to store things, but also to get more things',
+ 'notes' => [
+ 'this is a notice',
+ 'and another one, if really needed'
+ ],
+ 'columns' => []
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => '',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'another_field',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'last_one',
+ 'type' => 'date'
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddIndex',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\AddIndex',
+ 'table' => 'my_table',
+ 'description' => '',
+ 'notes' => [],
+ 'type' => 'primary'
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => '',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropColumn',
+ 'table' => 'other_table',
+ 'description' => 'field is not used anymore and replaced by \'last_one\'',
+ 'notes' => [],
+ 'name' => 'old_column',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\DropIndex',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => '',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'this_field',
+ 'type' => ''
+ ],
+ [
+ 'class' => 'OCP\\Migration\\Attributes\\ModifyColumn',
+ 'table' => 'other_table',
+ 'description' => '',
+ 'notes' => [],
+ 'name' => 'this_field',
+ 'type' => 'bigint'
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
+}