From b414b7dd2d2cd2d37ab50e032ca35ee0f13d89a2 Mon Sep 17 00:00:00 2001 From: Ivan Bragin Date: Wed, 13 May 2020 22:57:08 +0700 Subject: [PATCH] Updating deprecated @expectedException annotations. Adding asserting exception message. --- tests/Migrations/AtomizerTest.php | 6 +- tests/Migrations/BlueprintTest.php | 24 ++--- tests/Migrations/ExceptionsTest.php | 132 ++++++++++++++-------------- tests/Migrations/MigratorTest.php | 36 ++++---- 4 files changed, 99 insertions(+), 99 deletions(-) diff --git a/tests/Migrations/AtomizerTest.php b/tests/Migrations/AtomizerTest.php index 14e1b65..cd1e17c 100644 --- a/tests/Migrations/AtomizerTest.php +++ b/tests/Migrations/AtomizerTest.php @@ -303,11 +303,11 @@ public function testSetPrimaryKeys(): void $this->assertFalse($this->db->hasTable('sample')); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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 60d4a8a..b10c422 100644 --- a/tests/Migrations/BlueprintTest.php +++ b/tests/Migrations/BlueprintTest.php @@ -131,11 +131,11 @@ public function testCreateWithForeignAliased(): void $this->assertTrue($blueprint->getSchema()->exists()); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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') @@ -173,11 +173,11 @@ public function testUpdateTable(): void ->update(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ColumnException - */ 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') @@ -193,11 +193,11 @@ public function testUpdateTableError2(): void $blueprint->addColumn('value', 'int')->update(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ColumnException - */ 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') @@ -213,11 +213,11 @@ public function testUpdateTableError5(): void $blueprint->addColumn('value', 'int')->update(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\IndexException - */ 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 b1d068e..4d8c653 100644 --- a/tests/Migrations/ExceptionsTest.php +++ b/tests/Migrations/ExceptionsTest.php @@ -27,11 +27,11 @@ abstract class ExceptionsTest extends BaseTest { - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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); @@ -39,11 +39,11 @@ public function testDropNonExisted(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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); @@ -51,11 +51,11 @@ public function testCreateEmpty(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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(); @@ -67,11 +67,11 @@ public function testCreateDuplicate(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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(); @@ -79,11 +79,11 @@ public function testUpdateNonExisted(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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(); @@ -91,11 +91,11 @@ public function testRenameNonExisted(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\TableException - */ 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(); @@ -111,11 +111,11 @@ public function testRenameButBusy(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ColumnException - */ 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(); @@ -128,11 +128,11 @@ public function testDuplicateColumn(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\IndexException - */ 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(); @@ -145,11 +145,11 @@ public function testDropNonExistedIndex(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\IndexException - */ 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(); @@ -162,11 +162,11 @@ public function testAlterNonExistedIndex(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ColumnException - */ 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(); @@ -178,11 +178,11 @@ public function testAlterNonExistedColumn(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ColumnException - */ 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(); @@ -194,11 +194,11 @@ public function testRenameNonExistedColumn(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ColumnException - */ 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(); @@ -212,11 +212,11 @@ public function testRenameDuplicateExistedColumn(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -229,11 +229,11 @@ public function testAddForeignNoTarget(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -250,11 +250,11 @@ public function testAddForeignNoTargetColumn(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -267,11 +267,11 @@ public function testAlterForeignNoFK(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -289,11 +289,11 @@ public function testAlterForeignNoTable(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -315,11 +315,11 @@ public function testAlterForeignNoColumn(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -332,11 +332,11 @@ public function testDropNonExistedFK(): void $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\Operation\ForeignKeyException - */ 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(); @@ -373,29 +373,29 @@ public function testBadDateFormatMigrationFile(): void $this->repository->getMigrations(); } - /** - * @expectedException \Spiral\Migrations\Exception\RepositoryException - */ 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); } - /** - * @expectedException \Spiral\Migrations\Exception\RepositoryException - */ 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); } - /** - * @expectedException \Spiral\Migrations\Exception\RepositoryException - */ 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 71989ca..c9ef7f7 100644 --- a/tests/Migrations/MigratorTest.php +++ b/tests/Migrations/MigratorTest.php @@ -46,19 +46,19 @@ public function testRepository(): void $this->assertSame($this->repository, $this->migrator->getRepository()); } - /** - * @expectedException \Spiral\Migrations\Exception\MigrationException - */ public function testRunUnconfigured(): void { + $this->expectException(\Spiral\Migrations\Exception\MigrationException::class); + $this->expectExceptionMessage("Unable to run migration, Migrator not configured"); + $this->migrator->run(); } - /** - * @expectedException \Spiral\Migrations\Exception\MigrationException - */ public function testRollbackUnconfigured(): void { + $this->expectException(\Spiral\Migrations\Exception\MigrationException::class); + $this->expectExceptionMessage("Unable to run migration, Migrator not configured"); + $this->migrator->rollback(); } @@ -73,11 +73,11 @@ public function testCapsule(): void $this->assertTrue($capsule->getTable('test')->exists()); } - /** - * @expectedException \Spiral\Migrations\Exception\CapsuleException - */ 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([ @@ -85,29 +85,29 @@ public function testCapsuleException(): void ]); } - /** - * @expectedException \Spiral\Migrations\Exception\MigrationException - */ public function testNoState(): void { + $this->expectException(\Spiral\Migrations\Exception\MigrationException::class); + $this->expectExceptionMessage("Unable to get migration state, no state are set"); + $x = new TestMigration(); $x->up(); } - /** - * @expectedException \Spiral\Migrations\Exception\MigrationException - */ public function testNoCapsule(): void { + $this->expectException(\Spiral\Migrations\Exception\MigrationException::class); + $this->expectExceptionMessage("Unable to get table blueprint, no capsule are set"); + $x = new TestMigration(); $x->getTable(); } - /** - * @expectedException \Spiral\Migrations\Exception\MigrationException - */ public function testNoCapsule2(): void { + $this->expectException(\Spiral\Migrations\Exception\MigrationException::class); + $this->expectExceptionMessage("Unable to get database, no capsule are set"); + $x = new TestMigration(); $x->down(); }