From 3a7cf40aaa678bea1df143d2982d603b7a334eec Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 27 Nov 2019 15:27:18 +0100 Subject: Mode to modern phpunit Signed-off-by: Roeland Jago Douma --- tests/lib/DB/ConnectionTest.php | 16 +++--- tests/lib/DB/MigrationsTest.php | 68 +++++++++++++------------- tests/lib/DB/MigratorTest.php | 6 +-- tests/lib/DB/QueryBuilder/QueryBuilderTest.php | 2 +- 4 files changed, 46 insertions(+), 46 deletions(-) (limited to 'tests/lib/DB') diff --git a/tests/lib/DB/ConnectionTest.php b/tests/lib/DB/ConnectionTest.php index 4683c53d339..607674d7a38 100644 --- a/tests/lib/DB/ConnectionTest.php +++ b/tests/lib/DB/ConnectionTest.php @@ -42,12 +42,12 @@ class ConnectionTest extends \Test\TestCase { } } - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); } - public function tearDown(): void { + protected function tearDown(): void { parent::tearDown(); $this->connection->dropTable('table'); } @@ -157,10 +157,10 @@ class ConnectionTest extends \Test\TestCase { $this->assertEquals('bar', $this->getTextValueByIntergerField(1)); } - /** - * @expectedException \OCP\PreConditionNotMetException - */ + public function testSetValuesOverWritePreconditionFailed() { + $this->expectException(\OCP\PreConditionNotMetException::class); + $this->makeTestTable(); $this->connection->setValues('table', [ 'integerfield' => 1 @@ -335,10 +335,10 @@ class ConnectionTest extends \Test\TestCase { $this->assertEquals(0, $result); } - /** - * @expectedException \Doctrine\DBAL\Exception\UniqueConstraintViolationException - */ + public function testUniqueConstraintViolating() { + $this->expectException(\Doctrine\DBAL\Exception\UniqueConstraintViolationException::class); + $this->makeTestTable(); $testQuery = 'INSERT INTO `*PREFIX*table` (`integerfield`, `textfield`) VALUES(?, ?)'; diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index 8f38b3addd0..58f775febb0 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -36,7 +36,7 @@ class MigrationsTest extends \Test\TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | IDBConnection $db */ private $db; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->db = $this->createMock(Connection::class); @@ -60,27 +60,27 @@ class MigrationsTest extends \Test\TestCase { $this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Version 20170130180000 is unknown. - */ + public function testExecuteUnknownStep() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Version 20170130180000 is unknown.'); + $this->migrationService->executeStep('20170130180000'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage App not found - */ + public function testUnknownApp() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('App not found'); + $migrationService = new MigrationService('unknown-bloody-app', $this->db); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Migration step 'X' is unknown - */ + public function testExecuteStepWithUnknownClass() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Migration step \'X\' is unknown'); + $this->migrationService = $this->getMockBuilder(MigrationService::class) ->setMethods(['findMigrations']) ->setConstructorArgs(['testing', $this->db]) @@ -375,10 +375,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongTableName() { + $this->expectException(\InvalidArgumentException::class); + $table = $this->createMock(Table::class); $table->expects($this->any()) ->method('getName') @@ -400,10 +400,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithDefault() { + $this->expectException(\InvalidArgumentException::class); + $defaultName = 'PRIMARY'; if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) { $defaultName = \str_repeat('a', 27) . '_' . \str_repeat('b', 30) . '_seq'; @@ -453,10 +453,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithName() { + $this->expectException(\InvalidArgumentException::class); + $index = $this->createMock(Index::class); $index->expects($this->any()) ->method('getName') @@ -496,10 +496,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongColumnName() { + $this->expectException(\InvalidArgumentException::class); + $column = $this->createMock(Column::class); $column->expects($this->any()) ->method('getName') @@ -530,10 +530,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongIndexName() { + $this->expectException(\InvalidArgumentException::class); + $index = $this->createMock(Index::class); $index->expects($this->any()) ->method('getName') @@ -567,10 +567,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongForeignKeyName() { + $this->expectException(\InvalidArgumentException::class); + $foreignKey = $this->createMock(ForeignKeyConstraint::class); $foreignKey->expects($this->any()) ->method('getName') @@ -607,10 +607,10 @@ class MigrationsTest extends \Test\TestCase { self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testEnsureOracleIdentifierLengthLimitTooLongSequenceName() { + $this->expectException(\InvalidArgumentException::class); + $sequence = $this->createMock(Sequence::class); $sequence->expects($this->any()) ->method('getName') diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index ca778fd4e2f..e5cc28654e4 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -102,10 +102,10 @@ class MigratorTest extends \Test\TestCase { return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver; } - /** - * @expectedException \OC\DB\MigrationException - */ + public function testDuplicateKeyUpgrade() { + $this->expectException(\OC\DB\MigrationException::class); + if ($this->isSQLite()) { $this->markTestSkipped('sqlite does not throw errors when creating a new key on existing data'); } diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index e9878d33d85..a9542e2d616 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -1152,7 +1152,7 @@ class QueryBuilderTest extends \Test\TestCase { $actual = $qB->getLastInsertId(); $this->assertNotNull($actual); - $this->assertInternalType('int', $actual); + $this->assertIsInt($actual); $this->assertEquals($this->connection->lastInsertId('*PREFIX*properties'), $actual); $qB->delete('properties') -- cgit v1.2.3