1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00
appwrite/tests/unit/Migration/MigrationTest.php

137 lines
3.5 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Tests;
use Appwrite\Migration\Migration;
use PHPUnit\Framework\TestCase;
2022-05-20 00:17:18 +12:00
use ReflectionClass;
use ReflectionMethod;
2022-01-19 00:05:04 +13: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 21:55:49 +13:00
*
* @param Document $document
*/
protected function fixDocument(Document $document)
{
return $this->method->invokeArgs($this->migration, [
$this->method->invokeArgs($this->migration, [$document])
]);
}
2021-07-02 21:33:10 +12:00
/**
* Check versions array integrity.
*/
public function testMigrationVersions()
{
2022-05-20 00:17:18 +12:00
require_once __DIR__ . '/../../../app/init.php';
2021-07-02 21:33:10 +12:00
2022-01-19 00:05:04 +13:00
foreach (Migration::$versions as $class) {
2022-05-20 00:17:18 +12:00
$this->assertTrue(class_exists('Appwrite\\Migration\\Version\\' . $class));
2021-07-02 21:33:10 +12:00
}
// Test if current version exists
2022-05-20 00:17:18 +12:00
$this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions);
}
public function testHasDifference()
{
$this->assertFalse(Migration::hasDifference([], []));
$this->assertFalse(Migration::hasDifference([
2022-05-20 00:18:55 +12:00
'bool' => true,
'string' => 'abc',
'int' => 123,
'array' => ['a', 'b', 'c'],
'assoc' => [
2022-05-20 00:17:18 +12:00
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
]
], [
2022-05-20 00:18:55 +12:00
'bool' => true,
'string' => 'abc',
'int' => 123,
'array' => ['a', 'b', 'c'],
'assoc' => [
2022-05-20 00:17:18 +12:00
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
]
]));
$this->assertFalse(Migration::hasDifference([
'bool' => true,
'string' => 'abc',
'int' => 123,
'array' => ['a', 'b', 'c'],
'assoc' => [
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
]
], [
'string' => 'abc',
'assoc' => [
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
],
'int' => 123,
'array' => ['a', 'b', 'c'],
'bool' => true,
]));
2022-05-20 00:17:18 +12:00
$this->assertTrue(Migration::hasDifference([
'a' => true
], [
'b' => true
]));
$this->assertTrue(Migration::hasDifference([
'a' => 'true'
], [
'a' => true
]));
$this->assertTrue(Migration::hasDifference([
'a' => true
], [
'a' => false
]));
$this->assertTrue(Migration::hasDifference([
'nested' => [
'a' => true
]
], [
'nested' => []
]));
$this->assertTrue(Migration::hasDifference([
2022-05-20 00:18:55 +12:00
'assoc' => [
'bool' => true,
'string' => 'abc',
'int' => 123,
'array' => ['a', 'b', 'c']
2022-05-20 00:17:18 +12:00
]
], [
'nested' => [
'a' => true,
2022-05-20 00:18:55 +12:00
'int' => '123',
'array' => ['a', 'b', 'c']
2022-05-20 00:17:18 +12:00
]
]));
2021-07-02 21:33:10 +12:00
}
}