aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2021-08-12 10:03:21 +0200
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2021-09-01 15:09:18 +0200
commit98be3c32ea9dd9fdce4616c9b1d425c8cb979309 (patch)
treed2d440cadb9367a13daae175d56c0bca93b0e54f /tests
parent8f1efe9394ed0a6d4822b43fc7b7c7e6ebebc90a (diff)
migration branches for 5.0
Diffstat (limited to 'tests')
-rw-r--r--tests/_data/migrations/10_test_migration_ten.php (renamed from tests/unit/lib/classes/test-migrations/10_test_migration_ten.php)0
-rw-r--r--tests/_data/migrations/1_test_migration_one.php (renamed from tests/unit/lib/classes/test-migrations/1_test_migration_one.php)0
-rw-r--r--tests/_data/migrations/2.1_test_migration_two_one.php4
-rw-r--r--tests/_data/migrations/2_test_migration_two.php (renamed from tests/unit/lib/classes/test-migrations/2_test_migration_two.php)0
-rw-r--r--tests/unit/lib/classes/MigrationTest.php57
-rw-r--r--tests/unit/lib/classes/test-migrations/20190417_returns_instance.php5
6 files changed, 20 insertions, 46 deletions
diff --git a/tests/unit/lib/classes/test-migrations/10_test_migration_ten.php b/tests/_data/migrations/10_test_migration_ten.php
index 27e7d14..27e7d14 100644
--- a/tests/unit/lib/classes/test-migrations/10_test_migration_ten.php
+++ b/tests/_data/migrations/10_test_migration_ten.php
diff --git a/tests/unit/lib/classes/test-migrations/1_test_migration_one.php b/tests/_data/migrations/1_test_migration_one.php
index f0b36ce..f0b36ce 100644
--- a/tests/unit/lib/classes/test-migrations/1_test_migration_one.php
+++ b/tests/_data/migrations/1_test_migration_one.php
diff --git a/tests/_data/migrations/2.1_test_migration_two_one.php b/tests/_data/migrations/2.1_test_migration_two_one.php
new file mode 100644
index 0000000..13126d4
--- /dev/null
+++ b/tests/_data/migrations/2.1_test_migration_two_one.php
@@ -0,0 +1,4 @@
+<?php
+class TestMigrationTwoOne extends Migration
+{
+}
diff --git a/tests/unit/lib/classes/test-migrations/2_test_migration_two.php b/tests/_data/migrations/2_test_migration_two.php
index 14f4dd3..14f4dd3 100644
--- a/tests/unit/lib/classes/test-migrations/2_test_migration_two.php
+++ b/tests/_data/migrations/2_test_migration_two.php
diff --git a/tests/unit/lib/classes/MigrationTest.php b/tests/unit/lib/classes/MigrationTest.php
index 7085c9e..1f0bc98 100644
--- a/tests/unit/lib/classes/MigrationTest.php
+++ b/tests/unit/lib/classes/MigrationTest.php
@@ -13,9 +13,7 @@ class MigrationTest extends \Codeception\Test\Unit
public function setUp(): void
{
- $this->before = isset($GLOBALS['CACHING_ENABLE'])
- ? $GLOBALS['CACHING_ENABLE']
- : null;
+ $this->before = $GLOBALS['CACHING_ENABLE'] ?? null;
$GLOBALS['CACHING_ENABLE'] = false;
require_once 'lib/classes/StudipCache.class.php';
@@ -41,30 +39,26 @@ class MigrationTest extends \Codeception\Test\Unit
{
return new class() implements SchemaVersion
{
- private $versions = [];
+ private $versions = [0];
- public function get()
+ public function getBranch()
{
- return count($this->versions) > 0 ? max($this->versions) : 0;
+ return 0;
}
- public function contains($version)
+ public function getAllBranches()
{
- return in_array($version, $this->versions);
+ return array_keys($this->versions);
}
- public function add($version)
+ public function get($branch = 0)
{
- if (!$this->contains($version)) {
- $this->versions[] = $version;
- }
+ return $this->versions[$branch];
}
- public function remove($version)
+ public function set($version, $branch = 0)
{
- if ($this->contains($version)) {
- $this->versions = array_diff($this->versions, [$version]);
- }
+ $this->versions[$branch] = (int) $version;
}
};
}
@@ -72,29 +66,11 @@ class MigrationTest extends \Codeception\Test\Unit
private function getMigrator($schema_version = null)
{
return new Migrator(
- __DIR__ . '/test-migrations',
+ TEST_FIXTURES_PATH . 'migrations',
$schema_version ?: $this->getSchemaVersion()
);
}
- public function testSchemaVersion()
- {
- $schema_version = $this->getSchemaVersion();
- $this->assertSame(0, $schema_version->get());
-
- $schema_version->add(1);
- $this->assertTrue($schema_version->contains(1));
- $this->assertSame(1, $schema_version->get());
-
- $schema_version->add(2);
- $this->assertTrue($schema_version->contains(2));
- $this->assertSame(2, $schema_version->get());
-
- $schema_version->remove(1);
- $this->assertFalse($schema_version->contains(1));
- $this->assertSame(2, $schema_version->get());
- }
-
public function testRelevance()
{
$migrator = $this->getMigrator();
@@ -102,7 +78,7 @@ class MigrationTest extends \Codeception\Test\Unit
$relevant = $migrator->relevantMigrations(null);
$this->assertSame(4, count($relevant));
- $migrator->migrateTo(10);
+ $migrator->migrateTo(2);
$relevant = $migrator->relevantMigrations(null);
$this->assertSame(1, count($relevant));
@@ -113,7 +89,7 @@ class MigrationTest extends \Codeception\Test\Unit
$schema_version = $this->getSchemaVersion();
$migrator = $this->getMigrator($schema_version);
$migrator->migrateTo(null);
- $this->assertSame(20190417, $schema_version->get());
+ $this->assertSame(10, $schema_version->get());
$this->assertSame(0, count($migrator->relevantMigrations(null)));
return $schema_version;
@@ -133,13 +109,12 @@ class MigrationTest extends \Codeception\Test\Unit
public function testGaps()
{
$schema_version = $this->getSchemaVersion();
- $schema_version->add(2);
- $schema_version->add(10);
+ $schema_version->set(10);
$migrator = $this->getMigrator($schema_version);
$relevant = $migrator->relevantMigrations(null);
- $this->assertSame(2, count($relevant));
- $this->assertEquals([1, 20190417], array_keys($relevant));
+ $this->assertSame(1, count($relevant));
+ $this->assertEquals(['2.1'], array_keys($relevant));
}
}
diff --git a/tests/unit/lib/classes/test-migrations/20190417_returns_instance.php b/tests/unit/lib/classes/test-migrations/20190417_returns_instance.php
deleted file mode 100644
index c55e214..0000000
--- a/tests/unit/lib/classes/test-migrations/20190417_returns_instance.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<?php
-return new class() extends Migration
-{
-
-};