appwrite/tests/unit/Migration/MigrationTest.php

52 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2022-08-01 10:22:04 +00:00
namespace Tests\Unit\Migration;
use Appwrite\Migration\Migration;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
2022-01-18 11:05:04 +00:00
use Utopia\Database\Document;
abstract class MigrationTest extends TestCase
{
/**
* @var Migration
*/
protected Migration $migration;
/**
* @var ReflectionMethod
*/
protected ReflectionMethod $method;
/**
* Runs every document fix twice, to prevent corrupted data on multiple migrations.
2022-02-22 08:55:49 +00:00
*
* @param Document $document
*/
protected function fixDocument(Document $document)
{
return $this->method->invokeArgs($this->migration, [
$this->method->invokeArgs($this->migration, [$document])
]);
}
2021-07-02 09:33:10 +00:00
/**
* Check versions array integrity.
*/
2022-08-01 10:22:04 +00:00
public function testMigrationVersions(): void
2021-07-02 09:33:10 +00:00
{
2024-10-08 07:54:40 +00:00
require_once __DIR__ . '/../../../app/init.php';
2021-07-02 09:33:10 +00:00
2022-01-18 11:05:04 +00:00
foreach (Migration::$versions as $class) {
2022-05-19 12:17:18 +00:00
$this->assertTrue(class_exists('Appwrite\\Migration\\Version\\' . $class));
2021-07-02 09:33:10 +00:00
}
2025-07-18 05:25:48 +00:00
2021-07-02 09:33:10 +00:00
// Test if current version exists
2022-09-01 05:26:16 +00:00
// Only test official releases - skip if latest is release candidate
2022-09-01 05:26:49 +00:00
if (!(\str_contains(APP_VERSION_STABLE, 'RC'))) {
2022-09-01 05:26:16 +00:00
$this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions);
}
2022-05-19 12:17:18 +00:00
}
}