1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00

tests: add more migration tests

This commit is contained in:
Torsten Dittmann 2022-05-19 14:17:18 +02:00
parent 706ecc6b40
commit 0a559a3562
2 changed files with 71 additions and 6 deletions

View file

@ -124,7 +124,7 @@ abstract class Migration
$old = $document->getArrayCopy();
$new = call_user_func($callback, $document);
if (!$this->hasDifference($new->getArrayCopy(), $old)) {
if (!self::hasDifference($new->getArrayCopy(), $old)) {
return;
}
@ -158,14 +158,14 @@ abstract class Migration
* @param array $array2
* @return bool
*/
public function hasDifference(array $array1, array $array2): bool
public static function hasDifference(array $array1, array $array2): bool
{
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!isset($array2[$key]) || !is_array($array2[$key])) {
return true;
} else {
if ($this->hasDifference($value, $array2[$key])) {
if (self::hasDifference($value, $array2[$key])) {
return true;
}
}

View file

@ -4,6 +4,7 @@ namespace Appwrite\Tests;
use Appwrite\Migration\Migration;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
use Utopia\Database\Document;
@ -36,12 +37,76 @@ abstract class MigrationTest extends TestCase
*/
public function testMigrationVersions()
{
require_once __DIR__.'/../../../app/init.php';
require_once __DIR__ . '/../../../app/init.php';
foreach (Migration::$versions as $class) {
$this->assertTrue(class_exists('Appwrite\\Migration\\Version\\'.$class));
$this->assertTrue(class_exists('Appwrite\\Migration\\Version\\' . $class));
}
// Test if current version exists
//$this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions);
$this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions);
}
public function testHasDifference()
{
$this->assertFalse(Migration::hasDifference([], []));
$this->assertFalse(Migration::hasDifference([
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c'],
'nested' => [
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
]
], [
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c'],
'nested' => [
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
]
]));
$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([
'nested' => [
'a' => true,
'b' => 'abc',
'c' => 123,
'd' => ['a', 'b', 'c']
]
], [
'nested' => [
'a' => true,
'c' => '123',
'd' => ['a', 'b', 'c']
]
]));
}
}