diff --git a/tests/Migrations/AtomizerTest.php b/tests/Migrations/AtomizerTest.php index 5f8bb59..8bc78c6 100644 --- a/tests/Migrations/AtomizerTest.php +++ b/tests/Migrations/AtomizerTest.php @@ -305,6 +305,9 @@ public function testSetPrimaryKeys(): void public function testChangePrimaryKeys(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to set primary keys for table '.+'\.'.+', table already exists/"); + //Create thought migration $this->migrator->configure(); diff --git a/tests/Migrations/BlueprintTest.php b/tests/Migrations/BlueprintTest.php index 76a4c90..b10c422 100644 --- a/tests/Migrations/BlueprintTest.php +++ b/tests/Migrations/BlueprintTest.php @@ -134,6 +134,8 @@ public function testCreateWithForeignAliased(): void public function testUpdateTableError(): void { $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to create table '.+'\.'.+', table already exists/"); + $blueprint = new TableBlueprint($capsule = new Capsule($this->db), 'sample'); $blueprint->addColumn('id', 'primary') @@ -174,6 +176,8 @@ public function testUpdateTable(): void public function testUpdateTableError2(): void { $this->expectException(\Spiral\Migrations\Exception\Operation\ColumnException::class); + $this->expectExceptionMessageMatches("/Unable to create column '.+'\.'.+', column already exists/"); + $blueprint = new TableBlueprint($capsule = new Capsule($this->db), 'sample'); $blueprint->addColumn('id', 'primary') @@ -192,6 +196,8 @@ public function testUpdateTableError2(): void public function testUpdateTableError5(): void { $this->expectException(\Spiral\Migrations\Exception\Operation\ColumnException::class); + $this->expectExceptionMessageMatches("/Option '.+' are required to define column with type '.+'/"); + $blueprint = new TableBlueprint($capsule = new Capsule($this->db), 'sample'); $blueprint->addColumn('id', 'primary') @@ -210,6 +216,8 @@ public function testUpdateTableError5(): void public function testUpdateTableError3(): void { $this->expectException(\Spiral\Migrations\Exception\Operation\IndexException::class); + $this->expectExceptionMessageMatches("/Unable to create index '.+'\.(.+), index already exists/"); + $blueprint = new TableBlueprint($capsule = new Capsule($this->db), 'sample'); $blueprint->addColumn('id', 'primary') diff --git a/tests/Migrations/ExceptionsTest.php b/tests/Migrations/ExceptionsTest.php index e3b974e..20a44bf 100644 --- a/tests/Migrations/ExceptionsTest.php +++ b/tests/Migrations/ExceptionsTest.php @@ -32,6 +32,9 @@ abstract class ExceptionsTest extends BaseTest public function testDropNonExisted(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to drop table '.+'\.'.+', table does not exists/"); + //Create thought migration $this->migrator->configure(); $this->repository->registerMigration('m', DropNonExistedMigration::class); @@ -46,6 +49,9 @@ public function testDropNonExisted(): void public function testCreateEmpty(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to create table '.+'\.'.+', no columns were added/"); + //Create thought migration $this->migrator->configure(); $this->repository->registerMigration('m', CreateEmptyMigration::class); @@ -60,6 +66,9 @@ public function testCreateEmpty(): void public function testCreateDuplicate(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to create table '.+'\.'.+', table already exists/"); + //Create thought migration $this->migrator->configure(); @@ -79,6 +88,9 @@ public function testCreateDuplicate(): void public function testUpdateNonExisted(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to update table '.+'\.'.+', no table exists/"); + //Create thought migration $this->migrator->configure(); @@ -94,6 +106,9 @@ public function testUpdateNonExisted(): void public function testRenameNonExisted(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to rename table '.+'\.'.+', table does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -109,6 +124,9 @@ public function testRenameNonExisted(): void public function testRenameButBusy(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\TableException::class); + $this->expectExceptionMessageMatches("/Unable to rename table '.+'\.'.+', table '.+' already exists/"); + //Create thought migration $this->migrator->configure(); @@ -132,6 +150,9 @@ public function testRenameButBusy(): void public function testDuplicateColumn(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ColumnException::class); + $this->expectExceptionMessageMatches("/Unable to create column '.+'\.'.+', column already exists/"); + //Create thought migration $this->migrator->configure(); @@ -152,6 +173,9 @@ public function testDuplicateColumn(): void public function testDropNonExistedIndex(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\IndexException::class); + $this->expectExceptionMessageMatches("/Unable to drop index '.+'\.(.+), index does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -172,6 +196,9 @@ public function testDropNonExistedIndex(): void public function testAlterNonExistedIndex(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\IndexException::class); + $this->expectExceptionMessageMatches("/Unable to alter index '.+'\.(.+), no such index/"); + //Create thought migration $this->migrator->configure(); @@ -192,6 +219,9 @@ public function testAlterNonExistedIndex(): void public function testAlterNonExistedColumn(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ColumnException::class); + $this->expectExceptionMessageMatches("/Unable to alter column '.+'\.'.+', column does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -211,6 +241,9 @@ public function testAlterNonExistedColumn(): void public function testRenameNonExistedColumn(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ColumnException::class); + $this->expectExceptionMessageMatches("/Unable to rename column '.+'\.'.+', column does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -230,6 +263,9 @@ public function testRenameNonExistedColumn(): void public function testRenameDuplicateExistedColumn(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ColumnException::class); + $this->expectExceptionMessageMatches("/Unable to rename column '.+'\.'.+', column '.+' already exists/"); + //Create thought migration $this->migrator->configure(); @@ -251,6 +287,9 @@ public function testRenameDuplicateExistedColumn(): void public function testAddForeignNoTarget(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to add foreign key 'tests_sample'.'column', foreign table 'target' does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -272,6 +311,9 @@ public function testAddForeignNoTarget(): void public function testAddForeignNoTargetColumn(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to add foreign key '.+'\.'.+', foreign column '.+'\.'.+' does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -297,6 +339,9 @@ public function testAddForeignNoTargetColumn(): void public function testAlterForeignNoFK(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to alter foreign key '.+'\.(.+), key does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -317,6 +362,9 @@ public function testAlterForeignNoFK(): void public function testAlterForeignNoTable(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to alter foreign key '.+'\.'.+', foreign table '.+' does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -343,6 +391,9 @@ public function testAlterForeignNoTable(): void public function testAlterForeignNoColumn(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to alter foreign key '.+'\.'.+', foreign column '.+'\.'.+' does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -373,6 +424,9 @@ public function testAlterForeignNoColumn(): void public function testDropNonExistedFK(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to drop foreign key '.+'\.'.+', foreign key does not exists/"); + //Create thought migration $this->migrator->configure(); @@ -394,6 +448,9 @@ public function testDropNonExistedFK(): void public function testAddExisted(): void { + $this->expectException(\Spiral\Migrations\Exception\Operation\ForeignKeyException::class); + $this->expectExceptionMessageMatches("/Unable to add foreign key '.+'\.(.+), foreign key already exists/"); + //Create thought migration $this->migrator->configure(); @@ -439,6 +496,7 @@ public function testBadDateFormatMigrationFile(): void public function testDuplicateClassMigration(): void { $this->expectException(\Spiral\Migrations\Exception\RepositoryException::class); + $this->expectExceptionMessageMatches("/Unable to register migration '.+', migration already exists/"); $this->repository->registerMigration('unique_name_1', DuplicateColumnMigration::class); $this->repository->registerMigration('unique_name_2', DuplicateColumnMigration::class); } @@ -446,6 +504,7 @@ public function testDuplicateClassMigration(): void public function testDuplicateFileNameMigration(): void { $this->expectException(\Spiral\Migrations\Exception\RepositoryException::class); + $this->expectExceptionMessageMatches("/Unable to register migration 'camel_case_duplicate', migration under the same name already exists/"); $this->repository->registerMigration('camel_case_duplicate', DuplicateColumnMigration::class); $this->repository->registerMigration('camelCaseDuplicate', CreateEmptyMigration::class); } @@ -453,6 +512,7 @@ public function testDuplicateFileNameMigration(): void public function testInvalidMigration(): void { $this->expectException(\Spiral\Migrations\Exception\RepositoryException::class); + $this->expectExceptionMessageMatches("/Unable to register migration '.+', representing class does not exists/"); $this->repository->registerMigration('m', 'invalid'); } } diff --git a/tests/Migrations/MigratorTest.php b/tests/Migrations/MigratorTest.php index fcb376d..86ec7eb 100644 --- a/tests/Migrations/MigratorTest.php +++ b/tests/Migrations/MigratorTest.php @@ -132,6 +132,7 @@ public function testCapsule(): void public function testCapsuleException(): void { $this->expectException(\Spiral\Migrations\Exception\CapsuleException::class); + $this->expectExceptionMessageMatches("/Migration operation expected to be an instance of `.+`, `.+` given/"); $capsule = new Capsule($this->db); $capsule->execute([