From 85f8f6bfbad86b2ff73525f1f3700acc6fd46970 Mon Sep 17 00:00:00 2001 From: "Tim Peters (FaimMedia B.V.)" Date: Mon, 29 Apr 2024 18:05:21 +0200 Subject: [PATCH] Additional tests --- test/Migration/MigrationTest.php | 23 ++++++++++-- test/Migration/VersionTest.php | 61 ++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 test/Migration/VersionTest.php diff --git a/test/Migration/MigrationTest.php b/test/Migration/MigrationTest.php index d2a3d11..589b10e 100644 --- a/test/Migration/MigrationTest.php +++ b/test/Migration/MigrationTest.php @@ -4,8 +4,6 @@ use FaimMedia\Migration\Test\AbstractTestCase; -use PDO; - use FaimMedia\Migration\Exception; /** @@ -28,10 +26,31 @@ public function testFullMigration(): void { $this->migration->run(); + parent::assertSame($this->migrationCount(), 4); + parent::assertTrue(parent::tableExists('test')); parent::assertTrue(parent::tableExists('test_1')); parent::assertTrue(parent::tableExists('test_2')); parent::assertTrue(parent::tableExists('test_3')); parent::assertTrue(parent::tableExists('test_4')); + parent::assertTrue(parent::tableExists('new_table')); + } + + /** + * Test partial migration + */ + public function testVersion1Migration(): void + { + $this->migration->run('0001'); + + parent::assertSame($this->migrationCount(), 1); + + parent::assertTrue(parent::tableExists('test')); + + parent::assertFalse(parent::tableExists('test_1')); + parent::assertFalse(parent::tableExists('test_2')); + parent::assertFalse(parent::tableExists('test_3')); + parent::assertFalse(parent::tableExists('test_4')); + parent::assertFalse(parent::tableExists('new_table')); } } diff --git a/test/Migration/VersionTest.php b/test/Migration/VersionTest.php new file mode 100644 index 0000000..ea5edc0 --- /dev/null +++ b/test/Migration/VersionTest.php @@ -0,0 +1,61 @@ +migration->validateVersion(3); + } + + /** + * Test non existing path + */ + public function testExceptionNonExistingPath(): void + { + parent::expectException(Exception::class); + parent::expectExceptionCode(Exception::FOLDER_STRUCTURE); + + $this->migration->validateVersion('0999'); + } + + /** + * Full migration test + */ + public function testExceptionEmptyPath(): void + { + parent::expectException(Exception::class); + parent::expectExceptionCode(Exception::FOLDER_EMPTY); + + $versionNumber = '0999'; + $parentPath = sys_get_temp_dir() . '/' . substr(md5(uniqid()), 0, 10); + $randomPath = $parentPath . '/' . $versionNumber; + + mkdir($randomPath, 0775, true); + + $this->migration->setPath($parentPath); + $this->migration->validateVersion('0999'); + } +}