From 2423759738f91659a9297fe8abb786963594cabf Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 12 Sep 2018 15:04:15 +0200 Subject: [PATCH 1/4] Don't call static methods dynamically --- .../AbstractFileConfigurationTest.php | 26 +-- .../Tests/Configuration/ConfigurationTest.php | 8 +- .../ConnectionConfigurationLoaderTest.php | 2 +- .../Listeners/AutoCommitListenerTest.php | 6 +- .../Migrations/Tests/FileQueryWriterTest.php | 4 +- .../Tests/Finder/FinderTestCase.php | 4 +- .../Tests/Finder/RecursiveRegexFinderTest.php | 6 +- .../Tests/Functional/FunctionalTest.php | 2 +- .../Tests/Generator/DiffGeneratorTest.php | 30 ++-- .../Tests/Generator/FileBuilderTest.php | 2 +- .../Tests/Generator/GeneratorTest.php | 10 +- .../Tests/Generator/SqlGeneratorTest.php | 4 +- .../Tests/MigrationPlanCalculatorTest.php | 24 +-- .../Tests/MigrationRepositoryTest.php | 16 +- .../Migrations/Tests/MigratorTest.php | 22 +-- .../Tests/ParameterFormatterTest.php | 2 +- .../Doctrine/Migrations/Tests/RollupTest.php | 12 +- .../Migrations/Tests/SchemaDumperTest.php | 18 +- .../Console/Command/AbstractCommandTest.php | 20 +-- .../Tools/Console/Command/DialogSupport.php | 2 +- .../Tools/Console/Command/DiffCommandTest.php | 20 +-- .../Console/Command/DumpSchemaCommandTest.php | 18 +- .../Console/Command/ExecuteCommandTest.php | 50 +++--- .../Console/Command/GenerateCommandTest.php | 12 +- .../Console/Command/MigrateCommandTest.php | 158 +++++++++--------- .../Console/Command/MigrationStatusTest.php | 16 +- .../Console/Command/MigrationVersionTest.php | 4 +- .../Console/Command/RollupCommandTest.php | 8 +- .../Console/Command/StatusCommandTest.php | 46 ++--- .../Console/Command/UpToDateCommandTest.php | 2 +- .../Tools/Console/ConnectionLoaderTest.php | 4 +- .../Tests/Tools/Console/ConsoleRunnerTest.php | 2 +- .../Helper/ConfigurationHelperTest.php | 10 +- .../Helper/MigrationStatusInfosHelperTest.php | 30 ++-- .../Tests/Tracking/TableDefinitionTest.php | 8 +- .../Tests/Tracking/TableManipulatorTest.php | 30 ++-- .../Tests/Tracking/TableStatusTest.php | 28 ++-- .../Tests/Tracking/TableUpdaterTest.php | 44 ++--- .../Tests/Version/AliasResolverTest.php | 6 +- .../Migrations/Tests/Version/ExecutorTest.php | 44 ++--- .../Migrations/Tests/Version/VersionTest.php | 4 +- 41 files changed, 382 insertions(+), 382 deletions(-) diff --git a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php index 901926f4e7..ae21f453c9 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php @@ -30,7 +30,7 @@ public function testLoadChecksCurrentWorkingDirectory() : void $this->fileConfiguration->load($file); - $this->assertSame(__DIR__ . '/' . $file, $this->fileConfiguration->getFile()); + self::assertSame(__DIR__ . '/' . $file, $this->fileConfiguration->getFile()); chdir($cwd); } @@ -52,50 +52,50 @@ public function testSetConfiguration() : void 'setAllOrNothing', ]); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsNamespace') ->with('Doctrine'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsTableName') ->with('migration_version'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsColumnName') ->with('version_number'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsColumnLength') ->with(200); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsExecutedAtColumnName') ->with('executed_at'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsAreOrganizedByYearAndMonth'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setName') ->with('Migrations Test'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setMigrationsDirectory') ->with('migrations_directory'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('registerMigrationsFromDirectory') ->with('migrations_directory'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('registerMigration') ->with('001', 'Test'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setCustomTemplate') ->with('custom_template'); - $fileConfiguration->expects($this->once()) + $fileConfiguration->expects(self::once()) ->method('setAllOrNothing') ->with(true); diff --git a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php index 045ce926fb..05ba5c9385 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php @@ -167,7 +167,7 @@ public function testMasterSlaveConnectionAlwaysConnectsToMaster() : void { $connection = $this->createMock(MasterSlaveConnection::class); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('connect') ->with('master') ->willReturn(true); @@ -258,7 +258,7 @@ public function testGetQueryWriterCreatesAnInstanceIfItWasNotConfigured() : void $schemaManager = $this->createMock(AbstractSchemaManager::class); - $conn->expects($this->any()) + $conn->expects(self::any()) ->method('getSchemaManager') ->willReturn($schemaManager); @@ -294,11 +294,11 @@ public function testGetVersionData() : void 'executed_at' => '2018-05-16 11:14:40', ]; - $dependencyFactory->expects($this->once()) + $dependencyFactory->expects(self::once()) ->method('getMigrationRepository') ->willReturn($migrationRepository); - $migrationRepository->expects($this->once()) + $migrationRepository->expects(self::once()) ->method('getVersionData') ->with($version) ->willReturn($versionData); diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php index 56d3222a97..bf30f2d2cb 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php @@ -25,7 +25,7 @@ public function testChosenReturnsConfigurationConnection() : void { $connection = $this->createMock(Connection::class); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getConnection') ->willReturn($connection); diff --git a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php index 7c5791736b..e5aa360fa6 100644 --- a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php +++ b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php @@ -28,7 +28,7 @@ public function testListenerDoesNothingDuringADryRun() : void public function testListenerDoesNothingWhenConnecitonAutoCommitIsOn() : void { $this->willNotCommit(); - $this->conn->expects($this->once()) + $this->conn->expects(self::once()) ->method('isAutoCommit') ->willReturn(true); @@ -37,10 +37,10 @@ public function testListenerDoesNothingWhenConnecitonAutoCommitIsOn() : void public function testListenerDoesFinalCommitWhenAutoCommitIsOff() : void { - $this->conn->expects($this->once()) + $this->conn->expects(self::once()) ->method('isAutoCommit') ->willReturn(false); - $this->conn->expects($this->once()) + $this->conn->expects(self::once()) ->method('commit'); $this->listener->onMigrationsMigrated($this->createArgs(false)); diff --git a/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php b/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php index f3d890f3ea..5e62fe2362 100644 --- a/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php +++ b/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php @@ -46,7 +46,7 @@ public function testWrite( $migrationFileBuilder ); - $platform->expects($this->any()) + $platform->expects(self::any()) ->method('getCurrentTimestampSQL') ->willReturn('CURRENT_TIMESTAMP'); @@ -90,7 +90,7 @@ public function writeProvider() : array { $outputWriter = $this->createMock(OutputWriter::class); - $outputWriter->expects($this->atLeastOnce()) + $outputWriter->expects(self::atLeastOnce()) ->method('write') ->with($this->isType('string')); diff --git a/tests/Doctrine/Migrations/Tests/Finder/FinderTestCase.php b/tests/Doctrine/Migrations/Tests/Finder/FinderTestCase.php index 55bbec6111..184f7ce2b4 100644 --- a/tests/Doctrine/Migrations/Tests/Finder/FinderTestCase.php +++ b/tests/Doctrine/Migrations/Tests/Finder/FinderTestCase.php @@ -16,7 +16,7 @@ public function testClassesInMultipleNamespacesCanBeLoadedByTheFinder() : void { $versions = $this->finder->findMigrations(__DIR__ . '/_features/MultiNamespace'); - $this->assertSame([ + self::assertSame([ '0001' => 'TestMigrations\\Test\\Version0001', '0002' => 'TestMigrations\\TestOther\\Version0002', ], $versions); @@ -29,6 +29,6 @@ public function testOnlyClassesInTheProvidedNamespaceAreLoadedWhenNamespaceIsPro 'TestMigrations\\Test' ); - $this->assertSame(['0001' => 'TestMigrations\\Test\\Version0001'], $versions); + self::assertSame(['0001' => 'TestMigrations\\Test\\Version0001'], $versions); } } diff --git a/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php b/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php index 8aed304a4d..eabe38b91c 100644 --- a/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php +++ b/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php @@ -73,7 +73,7 @@ public function testFindMigrationsCanLocateClassesInNestedNamespacesAndDirectori { $versions = $this->finder->findMigrations(__DIR__ . '/_features/MultiNamespaceNested'); - $this->assertSame([ + self::assertSame([ '0001' => 'TestMigrations\\MultiNested\\Version0001', '0002' => 'TestMigrations\\MultiNested\\Deep\\Version0002', ], $versions); @@ -86,7 +86,7 @@ public function testMigrationsInSubnamespaceAreLoadedIfNamespaceIsParentNamespac 'TestMigrations\\MultiNested' ); - $this->assertSame([ + self::assertSame([ '0001' => 'TestMigrations\MultiNested\Version0001', '0002' => 'TestMigrations\MultiNested\Deep\Version0002', ], $versions); @@ -99,7 +99,7 @@ public function testOnlyMigrationsInTheProvidedNamespacesAreLoadedIfNamespaceIsP 'TestMigrations\\MultiNested\\Deep' ); - $this->assertSame(['0002' => 'TestMigrations\MultiNested\Deep\Version0002'], $versions); + self::assertSame(['0002' => 'TestMigrations\MultiNested\Deep\Version0002'], $versions); } protected function setUp() : void diff --git a/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php b/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php index 36518ad4bb..33c46f6f16 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php @@ -436,7 +436,7 @@ public function testMigrationWorksWhenNoCallsAreMadeToTheSchema() : void continue; } - $schema->expects($this->never())->method($method); + $schema->expects(self::never())->method($method); } } diff --git a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php index 4782849166..6f1abaf725 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php @@ -43,70 +43,70 @@ public function testGenerate() : void $fromSchema = $this->createMock(Schema::class); $toSchema = $this->createMock(Schema::class); - $this->dbalConfiguration->expects($this->once()) + $this->dbalConfiguration->expects(self::once()) ->method('setFilterSchemaAssetsExpression') ->with('/table_name1/'); - $this->dbalConfiguration->expects($this->once()) + $this->dbalConfiguration->expects(self::once()) ->method('getFilterSchemaAssetsExpression') ->willReturn('/table_name1/'); $table1 = $this->createMock(Table::class); - $table1->expects($this->once()) + $table1->expects(self::once()) ->method('getName') ->willReturn('schema.table_name1'); $table2 = $this->createMock(Table::class); - $table2->expects($this->once()) + $table2->expects(self::once()) ->method('getName') ->willReturn('schema.table_name2'); $table3 = $this->createMock(Table::class); - $table3->expects($this->once()) + $table3->expects(self::once()) ->method('getName') ->willReturn('schema.table_name3'); - $toSchema->expects($this->once()) + $toSchema->expects(self::once()) ->method('getTables') ->willReturn([$table1, $table2, $table3]); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('createSchema') ->willReturn($fromSchema); - $this->schemaProvider->expects($this->once()) + $this->schemaProvider->expects(self::once()) ->method('createSchema') ->willReturn($toSchema); - $toSchema->expects($this->at(1)) + $toSchema->expects(self::at(1)) ->method('dropTable') ->with('schema.table_name2'); - $toSchema->expects($this->at(2)) + $toSchema->expects(self::at(2)) ->method('dropTable') ->with('schema.table_name3'); - $fromSchema->expects($this->once()) + $fromSchema->expects(self::once()) ->method('getMigrateToSql') ->with($toSchema, $this->platform) ->willReturn(['UPDATE table SET value = 2']); - $fromSchema->expects($this->once()) + $fromSchema->expects(self::once()) ->method('getMigrateFromSql') ->with($toSchema, $this->platform) ->willReturn(['UPDATE table SET value = 1']); - $this->migrationSqlGenerator->expects($this->at(0)) + $this->migrationSqlGenerator->expects(self::at(0)) ->method('generate') ->with(['UPDATE table SET value = 2'], true, 80) ->willReturn('test1'); - $this->migrationSqlGenerator->expects($this->at(1)) + $this->migrationSqlGenerator->expects(self::at(1)) ->method('generate') ->with(['UPDATE table SET value = 1'], true, 80) ->willReturn('test2'); - $this->migrationGenerator->expects($this->once()) + $this->migrationGenerator->expects(self::once()) ->method('generateMigration') ->with('1234', 'test1', 'test2') ->willReturn('path'); diff --git a/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php b/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php index 071447f0f6..cf9f78dc4b 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php @@ -39,7 +39,7 @@ public function testBuildMigrationFile() : void $now = new DateTime('2018-09-01'); - $this->platform->expects($this->any()) + $this->platform->expects(self::any()) ->method('getCurrentTimestampSQL') ->willReturn('CURRENT_TIMESTAMP'); diff --git a/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php index c434615b13..7281360d9f 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php @@ -25,11 +25,11 @@ final class GeneratorTest extends TestCase public function testGenerateMigration() : void { - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsNamespace') ->willReturn('Test'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsDirectory') ->willReturn(sys_get_temp_dir()); @@ -55,7 +55,7 @@ public function testCustomTemplate() : void file_put_contents($customTemplate, 'custom template test'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getCustomTemplate') ->willReturn($customTemplate); @@ -73,7 +73,7 @@ public function testCustomTemplateThrowsInvalidArgumentExceptionWhenTemplateMiss $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The specified template "invalid" cannot be found or is not readable.'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getCustomTemplate') ->willReturn('invalid'); @@ -92,7 +92,7 @@ public function testCustomTemplateThrowsInvalidArgumentExceptionWhenTemplateEmpt $customTemplate )); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getCustomTemplate') ->willReturn($customTemplate); diff --git a/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php index 57a60f52fd..3144e92d47 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php @@ -43,11 +43,11 @@ public function testGenerate() : void $expectedCode = sprintf($expectedCode, $formattedUpdate); - $this->configuration->expects($this->any()) + $this->configuration->expects(self::any()) ->method('getMigrationsTableName') ->willReturn('migrations_table_name'); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getName') ->willReturn('mysql'); diff --git a/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php b/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php index 21dc0388bd..a4a8d2ef96 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php +++ b/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php @@ -21,26 +21,26 @@ final class MigrationPlanCalculatorTest extends TestCase public function testGetMigrationsToExecuteUp() : void { $version1 = $this->createMock(Version::class); - $version1->expects($this->any()) + $version1->expects(self::any()) ->method('getVersion') ->willReturn('01'); $version2 = $this->createMock(Version::class); - $version2->expects($this->any()) + $version2->expects(self::any()) ->method('getVersion') ->willReturn('02'); $version3 = $this->createMock(Version::class); - $version3->expects($this->any()) + $version3->expects(self::any()) ->method('getVersion') ->willReturn('03'); $version4 = $this->createMock(Version::class); - $version4->expects($this->any()) + $version4->expects(self::any()) ->method('getVersion') ->willReturn('04'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigrations') ->willReturn([ '01' => $version1, @@ -49,7 +49,7 @@ public function testGetMigrationsToExecuteUp() : void '04' => $version4, ]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigratedVersions') ->willReturn([ '02', @@ -72,26 +72,26 @@ public function testGetMigrationsToExecuteUp() : void public function testGetMigrationsToExecuteDown() : void { $version1 = $this->createMock(Version::class); - $version1->expects($this->any()) + $version1->expects(self::any()) ->method('getVersion') ->willReturn('01'); $version2 = $this->createMock(Version::class); - $version2->expects($this->any()) + $version2->expects(self::any()) ->method('getVersion') ->willReturn('02'); $version3 = $this->createMock(Version::class); - $version3->expects($this->any()) + $version3->expects(self::any()) ->method('getVersion') ->willReturn('03'); $version4 = $this->createMock(Version::class); - $version4->expects($this->any()) + $version4->expects(self::any()) ->method('getVersion') ->willReturn('04'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigrations') ->willReturn([ '01' => $version1, @@ -100,7 +100,7 @@ public function testGetMigrationsToExecuteDown() : void '04' => $version4, ]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigratedVersions') ->willReturn([ '02', diff --git a/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php b/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php index 40956d7b17..e9967984f6 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php +++ b/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php @@ -39,12 +39,12 @@ public function testGetDeltaVersionReturnsNull() : void public function testGetVersions() : void { $version1 = $this->createMock(Version::class); - $version1->expects($this->once()) + $version1->expects(self::once()) ->method('getVersion') ->willReturn('01'); $version2 = $this->createMock(Version::class); - $version2->expects($this->once()) + $version2->expects(self::once()) ->method('getVersion') ->willReturn('02'); @@ -66,21 +66,21 @@ public function testGetVersionData() : void { $version = $this->createMock(Version::class); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('connect'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('createMigrationTable'); - $this->configuration->expects($this->exactly(2)) + $this->configuration->expects(self::exactly(2)) ->method('getQuotedMigrationsColumnName') ->willReturn('version'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getQuotedMigrationsExecutedAtColumnName') ->willReturn('executed_at'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsTableName') ->willReturn('versions'); @@ -89,7 +89,7 @@ public function testGetVersionData() : void 'executed_at' => '2018-05-16 11:14:40', ]; - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('fetchAssoc') ->with('SELECT version, executed_at FROM versions WHERE version = ?') ->willReturn($versionData); diff --git a/tests/Doctrine/Migrations/Tests/MigratorTest.php b/tests/Doctrine/Migrations/Tests/MigratorTest.php index c84c3cd995..4accaf47c9 100644 --- a/tests/Doctrine/Migrations/Tests/MigratorTest.php +++ b/tests/Doctrine/Migrations/Tests/MigratorTest.php @@ -64,24 +64,24 @@ public function testWriteSqlDown() : void ->setMethods(['getSql']) ->getMock(); - $migration->expects($this->once()) + $migration->expects(self::once()) ->method('getSql') ->with('1') ->willReturn($sql); - $migrationRepository->expects($this->once()) + $migrationRepository->expects(self::once()) ->method('getCurrentVersion') ->willReturn('5'); - $outputWriter->expects($this->once()) + $outputWriter->expects(self::once()) ->method('write') ->with("-- Migrating from 5 to 1\n"); - $configuration->expects($this->once()) + $configuration->expects(self::once()) ->method('getQueryWriter') ->willReturn($queryWriter); - $queryWriter->expects($this->once()) + $queryWriter->expects(self::once()) ->method('write') ->with('/path', Direction::DOWN, $sql); @@ -142,7 +142,7 @@ public function testGetSql(?string $to) : void $expected = ['something']; - $migration->expects($this->once()) + $migration->expects(self::once()) ->method('migrate') ->with($to) ->willReturn($expected); @@ -175,7 +175,7 @@ public function testWriteSqlFile(string $path, string $from, ?string $to, array ->with($path, new RegularExpression('/(up|down)/'), $getSqlReturn) ->willReturn(true); - $outputWriter->expects($this->atLeastOnce()) + $outputWriter->expects(self::atLeastOnce()) ->method('write'); /** @var Configuration|PHPUnit_Framework_MockObject_MockObject $migration */ @@ -184,15 +184,15 @@ public function testWriteSqlFile(string $path, string $from, ?string $to, array $dependencyFactory = $this->createMock(DependencyFactory::class); $migrationRepository = $this->createMock(MigrationRepository::class); - $config->expects($this->once()) + $config->expects(self::once()) ->method('getDependencyFactory') ->willReturn($dependencyFactory); - $dependencyFactory->expects($this->once()) + $dependencyFactory->expects(self::once()) ->method('getMigrationRepository') ->willReturn($migrationRepository); - $dependencyFactory->expects($this->once()) + $dependencyFactory->expects(self::once()) ->method('getOutputWriter') ->willReturn($outputWriter); @@ -216,7 +216,7 @@ public function testWriteSqlFile(string $path, string $from, ?string $to, array ->setMethods(['getSql']) ->getMock(); - $migration->expects($this->once()) + $migration->expects(self::once()) ->method('getSql') ->with($to) ->willReturn($getSqlReturn); diff --git a/tests/Doctrine/Migrations/Tests/ParameterFormatterTest.php b/tests/Doctrine/Migrations/Tests/ParameterFormatterTest.php index 4a66e46b81..377b4a9fa9 100644 --- a/tests/Doctrine/Migrations/Tests/ParameterFormatterTest.php +++ b/tests/Doctrine/Migrations/Tests/ParameterFormatterTest.php @@ -64,7 +64,7 @@ protected function setUp() : void $this->platform = $this->createMock(AbstractPlatform::class); - $this->connection->expects($this->any()) + $this->connection->expects(self::any()) ->method('getDatabasePlatform') ->willReturn($this->platform); diff --git a/tests/Doctrine/Migrations/Tests/RollupTest.php b/tests/Doctrine/Migrations/Tests/RollupTest.php index ac3dd31d55..c828b37815 100644 --- a/tests/Doctrine/Migrations/Tests/RollupTest.php +++ b/tests/Doctrine/Migrations/Tests/RollupTest.php @@ -31,7 +31,7 @@ public function testRollupNoMigrtionsFoundException() : void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('No migrations found.'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn([]); @@ -51,7 +51,7 @@ public function testRollupTooManyMigrationsException() : void '02' => $version2, ]; - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn($versions); @@ -64,19 +64,19 @@ public function testRollup() : void $versions = ['01' => $version1]; - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn($versions); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsTableName') ->willReturn('versions'); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('executeQuery') ->with('DELETE FROM versions'); - $version1->expects($this->once()) + $version1->expects(self::once()) ->method('markMigrated'); $this->assertSame($version1, $this->rollup->rollup()); diff --git a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php index 7e44d5221b..3af800d9c1 100644 --- a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php +++ b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php @@ -38,11 +38,11 @@ public function testDumpNoTablesException() : void $schema = $this->createMock(Schema::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('createSchema') ->willReturn($schema); - $schema->expects($this->once()) + $schema->expects(self::once()) ->method('getTables') ->willReturn([]); @@ -55,33 +55,33 @@ public function testDump() : void $schema = $this->createMock(Schema::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('createSchema') ->willReturn($schema); - $schema->expects($this->once()) + $schema->expects(self::once()) ->method('getTables') ->willReturn([$table]); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getCreateTableSQL') ->willReturn(['CREATE TABLE test']); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDropTableSQL') ->willReturn('DROP TABLE test'); - $this->migrationSqlGenerator->expects($this->at(0)) + $this->migrationSqlGenerator->expects(self::at(0)) ->method('generate') ->with(['CREATE TABLE test']) ->willReturn('up'); - $this->migrationSqlGenerator->expects($this->at(1)) + $this->migrationSqlGenerator->expects(self::at(1)) ->method('generate') ->with(['DROP TABLE test']) ->willReturn('down'); - $this->migrationGenerator->expects($this->once()) + $this->migrationGenerator->expects(self::once()) ->method('generateMigration') ->with('1234', 'up', 'down') ->willReturn('/path/to/migration.php'); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php index e917377eb8..f14cc2f5dc 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php @@ -77,7 +77,7 @@ public function testSetConnection() : void $command->setConnection($connection); - $this->assertSame($connection, $command->getConnection()); + self::assertSame($connection, $command->getConnection()); } public function testGetMigrationConfigurationDefaultsToConnection() : void @@ -89,7 +89,7 @@ public function testGetMigrationConfigurationDefaultsToConnection() : void $command = new TestAbstractCommand(); $command->setMigrationConfiguration($configuration); - $this->assertSame($configuration, $command->getConfiguration($input, $output)); + self::assertSame($configuration, $command->getConfiguration($input, $output)); } /** @@ -103,8 +103,8 @@ public function testInjectedMigrationConfigurationIsBeingReturned() : void ->getMock(); $input->method('getOption') - ->with($this->logicalOr($this->equalTo('db-configuration'), $this->equalTo('configuration'))) - ->will($this->returnValue(null)); + ->with(self::logicalOr(self::equalTo('db-configuration'), self::equalTo('configuration'))) + ->will(self::returnValue(null)); $configuration = $this->createMock(Configuration::class); @@ -122,8 +122,8 @@ public function testMigrationConfigurationReturnsConnectionFromHelperSet() : voi ->getMock(); $input->method('getOption') - ->with($this->logicalOr($this->equalTo('db-configuration'), $this->equalTo('configuration'))) - ->will($this->returnValue(null)); + ->with(self::logicalOr(self::equalTo('db-configuration'), self::equalTo('configuration'))) + ->will(self::returnValue(null)); $actualConfiguration = $this->invokeMigrationConfigurationGetter($input); @@ -142,7 +142,7 @@ public function testMigrationConfigurationReturnsConnectionFromInputOption() : v ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['db-configuration', __DIR__ . '/_files/db-config.php'], ])); @@ -163,7 +163,7 @@ public function testMigrationConfigurationReturnsConfigurationFileOption() : voi ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['configuration', __DIR__ . '/_files/config.yml'], ])); @@ -217,7 +217,7 @@ public function testMigrationsConfigurationFromCommandLineOverridesInjectedConfi ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['configuration', __DIR__ . '/_files/config.yml'], ])); @@ -247,7 +247,7 @@ public function testInjectedConfigurationIsPreferedOverConfigFileIsCurrentWorkin ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['configuration', null], ])); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DialogSupport.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DialogSupport.php index aee92f62ef..3c38e0b739 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DialogSupport.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DialogSupport.php @@ -22,7 +22,7 @@ protected function configureDialogs(Application $app) : void protected function willAskConfirmationAndReturn(bool $bool) : void { - $this->questions->expects($this->once()) + $this->questions->expects(self::once()) ->method('ask') ->willReturn($bool); } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php index b988107010..f3c4b9df39 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php @@ -27,44 +27,44 @@ public function testExecute() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('generateVersionNumber') ->willReturn('1234'); - $input->expects($this->at(0)) + $input->expects(self::at(0)) ->method('getOption') ->with('filter-expression') ->willReturn('filter expression'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('formatted') ->willReturn(true); - $input->expects($this->at(2)) + $input->expects(self::at(2)) ->method('getOption') ->with('line-length') ->willReturn(80); - $input->expects($this->at(3)) + $input->expects(self::at(3)) ->method('getOption') ->with('editor-cmd') ->willReturn('mate'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('generateVersionNumber') ->willReturn('1234'); - $this->migrationDiffGenerator->expects($this->once()) + $this->migrationDiffGenerator->expects(self::once()) ->method('generate') ->with('1234', 'filter expression', true, 80) ->willReturn('/path/to/migration.php'); - $this->diffCommand->expects($this->once()) + $this->diffCommand->expects(self::once()) ->method('procOpen') ->with('mate', '/path/to/migration.php'); - $output->expects($this->once()) + $output->expects(self::once()) ->method('writeln') ->with([ 'Generated new migration class to "/path/to/migration.php"', @@ -88,7 +88,7 @@ protected function setUp() : void $this->diffCommand->setMigrationConfiguration($this->configuration); - $this->diffCommand->expects($this->once()) + $this->diffCommand->expects(self::once()) ->method('createMigrationDiffGenerator') ->willReturn($this->migrationDiffGenerator); } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php index ebcc32f4b0..44edb8dbee 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php @@ -44,7 +44,7 @@ public function testExecuteThrowsRuntimeException() : void $versions = [$version]; - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn($versions); @@ -56,36 +56,36 @@ public function testExecute() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->at(0)) + $input->expects(self::at(0)) ->method('getOption') ->with('formatted') ->willReturn(true); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('line-length') ->willReturn(80); - $input->expects($this->at(2)) + $input->expects(self::at(2)) ->method('getOption') ->with('editor-cmd') ->willReturn('test'); $versions = []; - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn($versions); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('generateVersionNumber') ->willReturn('1234'); - $this->schemaDumper->expects($this->once()) + $this->schemaDumper->expects(self::once()) ->method('dump') ->with('1234', true, 80); - $output->expects($this->once()) + $output->expects(self::once()) ->method('writeln') ->with([ 'Dumped your schema to a new migration class at ""', @@ -107,7 +107,7 @@ protected function setUp() : void $this->migrationRepository = $this->createMock(MigrationRepository::class); $this->schemaDumper = $this->createMock(SchemaDumper::class); - $this->dependencyFactory->expects($this->any()) + $this->dependencyFactory->expects(self::any()) ->method('getSchemaDumper') ->willReturn($this->schemaDumper); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php index 2f9ab164e8..c89bcfd02a 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php @@ -28,27 +28,27 @@ public function testWriteSqlCustomPath() : void $output = $this->createMock(OutputInterface::class); $version = $this->createMock(Version::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn($versionName); - $input->expects($this->at(3)) + $input->expects(self::at(3)) ->method('getOption') ->with('write-sql') ->willReturn('/path'); - $input->expects($this->at(4)) + $input->expects(self::at(4)) ->method('getOption') ->with('down') ->willReturn(true); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersion') ->with($versionName) ->willReturn($version); - $version->expects($this->once()) + $version->expects(self::once()) ->method('writeSqlFile') ->with('/path', 'down'); @@ -63,27 +63,27 @@ public function testWriteSqlCurrentWorkingDirectory() : void $output = $this->createMock(OutputInterface::class); $version = $this->createMock(Version::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn($versionName); - $input->expects($this->at(3)) + $input->expects(self::at(3)) ->method('getOption') ->with('write-sql') ->willReturn(null); - $input->expects($this->at(4)) + $input->expects(self::at(4)) ->method('getOption') ->with('down') ->willReturn(true); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersion') ->with($versionName) ->willReturn($version); - $version->expects($this->once()) + $version->expects(self::once()) ->method('writeSqlFile') ->with(getcwd(), 'down'); @@ -98,37 +98,37 @@ public function testExecute() : void $output = $this->createMock(OutputInterface::class); $version = $this->createMock(Version::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn($versionName); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('query-time') ->willReturn(true); - $input->expects($this->at(2)) + $input->expects(self::at(2)) ->method('getOption') ->with('dry-run') ->willReturn(true); - $input->expects($this->at(3)) + $input->expects(self::at(3)) ->method('getOption') ->with('write-sql') ->willReturn(false); - $input->expects($this->at(4)) + $input->expects(self::at(4)) ->method('getOption') ->with('down') ->willReturn(true); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersion') ->with($versionName) ->willReturn($version); - $version->expects($this->once()) + $version->expects(self::once()) ->method('execute') ->with('down'); @@ -143,41 +143,41 @@ public function testExecuteCancel() : void $output = $this->createMock(OutputInterface::class); $version = $this->createMock(Version::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn($versionName); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('query-time') ->willReturn(true); - $input->expects($this->at(2)) + $input->expects(self::at(2)) ->method('getOption') ->with('dry-run') ->willReturn(false); - $input->expects($this->at(3)) + $input->expects(self::at(3)) ->method('getOption') ->with('write-sql') ->willReturn(false); - $input->expects($this->at(4)) + $input->expects(self::at(4)) ->method('getOption') ->with('down') ->willReturn(true); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersion') ->with($versionName) ->willReturn($version); - $this->executeCommand->expects($this->once()) + $this->executeCommand->expects(self::once()) ->method('canExecute') ->willReturn(false); - $version->expects($this->never()) + $version->expects(self::never()) ->method('execute'); self::assertSame(1, $this->executeCommand->execute($input, $output)); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php index b3555a2ad9..4ab0551563 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php @@ -31,25 +31,25 @@ public function testExecute() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getOption') ->with('editor-cmd') ->willReturn('mate'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('generateVersionNumber') ->willReturn('1234'); - $this->migrationGenerator->expects($this->once()) + $this->migrationGenerator->expects(self::once()) ->method('generateMigration') ->with('1234') ->willReturn('/path/to/migration.php'); - $this->generateCommand->expects($this->once()) + $this->generateCommand->expects(self::once()) ->method('procOpen') ->with('mate', '/path/to/migration.php'); - $output->expects($this->once()) + $output->expects(self::once()) ->method('writeln') ->with([ 'Generated new migration class to "/path/to/migration.php"', @@ -68,7 +68,7 @@ protected function setUp() : void $this->dependencyFactory = $this->createMock(DependencyFactory::class); $this->migrationGenerator = $this->createMock(Generator::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrationGenerator') ->willReturn($this->migrationGenerator); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index ffdb600150..dfcf3cba2a 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -30,16 +30,16 @@ public function testExecuteCouldNotResolveAlias() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('1234'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('1234') ->willReturn(''); @@ -52,21 +52,21 @@ public function testExecuteAlreadyAtFirstVersion() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn(null); - $output->expects($this->at(4)) + $output->expects(self::at(4)) ->method('writeln') ->with('Already at first version.'); @@ -78,21 +78,21 @@ public function testExecuteAlreadyAtLatestVersion() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('next'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('next') ->willReturn(null); - $output->expects($this->at(4)) + $output->expects(self::at(4)) ->method('writeln') ->with('Already at latest version.'); @@ -104,21 +104,21 @@ public function testExecuteTheDeltaCouldNotBeReached() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('current-1'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('current-1') ->willReturn(null); - $output->expects($this->at(4)) + $output->expects(self::at(4)) ->method('writeln') ->with('The delta couldn\'t be reached.'); @@ -130,21 +130,21 @@ public function testExecuteUnknownVersion() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('unknown'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('unknown') ->willReturn(null); - $output->expects($this->at(4)) + $output->expects(self::at(4)) ->method('writeln') ->with('Unknown version: unknown'); @@ -156,25 +156,25 @@ public function testExecutedUnavailableMigrationsCancel() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->once()) + $this->migrateCommand->expects(self::once()) ->method('canExecute') ->willReturn(false); @@ -188,38 +188,38 @@ public function testExecuteWriteSqlCustomPath() : void $migration = $this->createMock(Migrator::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrator') ->willReturn($migration); - $migration->expects($this->once()) + $migration->expects(self::once()) ->method('writeSqlFile') ->with('test', '1234'); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('write-sql') ->willReturn('test'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->once()) + $this->migrateCommand->expects(self::once()) ->method('canExecute') ->willReturn(true); @@ -233,38 +233,38 @@ public function testExecuteWriteSqlCurrentWorkingDirectory() : void $migrator = $this->createMock(Migrator::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrator') ->willReturn($migrator); - $migrator->expects($this->once()) + $migrator->expects(self::once()) ->method('writeSqlFile') ->with(getcwd(), '1234'); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('write-sql') ->willReturn(null); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->once()) + $this->migrateCommand->expects(self::once()) ->method('canExecute') ->willReturn(true); @@ -278,44 +278,44 @@ public function testExecuteMigrate() : void $migrator = $this->createMock(Migrator::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrator') ->willReturn($migrator); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('write-sql') ->willReturn(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->at(0)) + $this->migrateCommand->expects(self::at(0)) ->method('canExecute') ->with('Are you sure you wish to continue? (y/n)') ->willReturn(true); - $this->migrateCommand->expects($this->at(1)) + $this->migrateCommand->expects(self::at(1)) ->method('canExecute') ->with('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)') ->willReturn(true); - $migrator->expects($this->once()) + $migrator->expects(self::once()) ->method('migrate') ->with('1234'); @@ -329,64 +329,64 @@ public function testExecuteMigrateAllOrNothing() : void $migrator = $this->createMock(Migrator::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrator') ->willReturn($migrator); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('write-sql') ->willReturn(false); - $input->expects($this->at(2)) + $input->expects(self::at(2)) ->method('getOption') ->with('allow-no-migration') ->willReturn(false); - $input->expects($this->at(3)) + $input->expects(self::at(3)) ->method('getOption') ->with('query-time') ->willReturn(false); - $input->expects($this->at(4)) + $input->expects(self::at(4)) ->method('getOption') ->with('dry-run') ->willReturn(false); - $input->expects($this->at(5)) + $input->expects(self::at(5)) ->method('getOption') ->with('all-or-nothing') ->willReturn(true); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->at(0)) + $this->migrateCommand->expects(self::at(0)) ->method('canExecute') ->with('Are you sure you wish to continue? (y/n)') ->willReturn(true); - $this->migrateCommand->expects($this->at(1)) + $this->migrateCommand->expects(self::at(1)) ->method('canExecute') ->with('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)') ->willReturn(true); - $migrator->expects($this->once()) + $migrator->expects(self::once()) ->method('migrate') ->with('1234'); @@ -400,39 +400,39 @@ public function testExecuteMigrateCancelExecutedUnavailableMigrations() : void $migrator = $this->createMock(Migrator::class); - $this->dependencyFactory->expects($this->never()) + $this->dependencyFactory->expects(self::never()) ->method('getMigrator') ->willReturn($migrator); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('write-sql') ->willReturn(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->once()) + $this->migrateCommand->expects(self::once()) ->method('canExecute') ->with('Are you sure you wish to continue? (y/n)') ->willReturn(false); - $migrator->expects($this->never()) + $migrator->expects(self::never()) ->method('migrate'); self::assertSame(1, $this->migrateCommand->execute($input, $output)); @@ -445,44 +445,44 @@ public function testExecuteMigrateCancel() : void $migrator = $this->createMock(Migrator::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrator') ->willReturn($migrator); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getArgument') ->with('version') ->willReturn('prev'); - $input->expects($this->at(1)) + $input->expects(self::at(1)) ->method('getOption') ->with('write-sql') ->willReturn(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('setIsDryRun') ->with(false); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('resolveVersionAlias') ->with('prev') ->willReturn('1234'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1235']); - $this->migrateCommand->expects($this->at(0)) + $this->migrateCommand->expects(self::at(0)) ->method('canExecute') ->with('Are you sure you wish to continue? (y/n)') ->willReturn(true); - $this->migrateCommand->expects($this->at(1)) + $this->migrateCommand->expects(self::at(1)) ->method('canExecute') ->with('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)') ->willReturn(false); - $migrator->expects($this->never()) + $migrator->expects(self::never()) ->method('migrate'); self::assertSame(1, $this->migrateCommand->execute($input, $output)); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php index be25472d89..68b9965e9e 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php @@ -64,27 +64,27 @@ protected function assertVersion(string $alias, ?string $version, string $label, ->getMock(); $configuration - ->expects($this->exactly(4)) + ->expects(self::exactly(4)) ->method('resolveVersionAlias') - ->will($this->returnCallback(static function ($argAlias) use ($alias, $version) { + ->will(self::returnCallback(static function ($argAlias) use ($alias, $version) { return $argAlias === $alias ? $version : '999'; })); $configuration ->method('getDateTime') - ->will($this->returnValue('FORMATTED')); + ->will(self::returnValue('FORMATTED')); $configuration ->method('getAvailableVersions') - ->will($this->returnValue([])); + ->will(self::returnValue([])); $configuration->setMigrationsNamespace('DoctrineMigrations'); $configuration->setMigrationsDirectory($this->migrationDirectory); $command - ->expects($this->once()) + ->expects(self::once()) ->method('getMigrationConfiguration') - ->will($this->returnValue($configuration)); + ->will(self::returnValue($configuration)); $commandTester = new CommandTester($command); $commandTester->execute( @@ -121,9 +121,9 @@ public function testShowVersions() : void ->getMock(); $command - ->expects($this->once()) + ->expects(self::once()) ->method('getMigrationConfiguration') - ->will($this->returnValue($configuration)); + ->will(self::returnValue($configuration)); $commandTester = new CommandTester($command); $commandTester->execute( diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php index 254a4319b4..19eff144d9 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php @@ -33,9 +33,9 @@ protected function setUp() : void $this->configuration->setMigrationsDirectory(sys_get_temp_dir()); $this->command - ->expects($this->once()) + ->expects(self::once()) ->method('getMigrationConfiguration') - ->will($this->returnValue($this->configuration)); + ->will(self::returnValue($this->configuration)); } /** diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php index c1840ff126..9f75197ad6 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php @@ -29,15 +29,15 @@ public function testExecute() : void $output = $this->createMock(OutputInterface::class); $version = $this->createMock(Version::class); - $version->expects($this->once()) + $version->expects(self::once()) ->method('getVersion') ->willReturn('1234'); - $this->rollup->expects($this->once()) + $this->rollup->expects(self::once()) ->method('rollup') ->willReturn($version); - $output->expects($this->once()) + $output->expects(self::once()) ->method('writeln') ->with('Rolled up migrations to version 1234'); @@ -49,7 +49,7 @@ protected function setUp() : void $this->rollup = $this->createMock(Rollup::class); $this->dependencyFactory = $this->createMock(DependencyFactory::class); - $this->dependencyFactory->expects($this->any()) + $this->dependencyFactory->expects(self::any()) ->method('getRollup') ->willReturn($this->rollup); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php index 9baff4d341..e4e27453eb 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php @@ -38,11 +38,11 @@ public function testExecute() : void $input = $this->createMock(InputInterface::class); $output = $this->createMock(OutputInterface::class); - $this->migrationStatusInfosHelper->expects($this->once()) + $this->migrationStatusInfosHelper->expects(self::once()) ->method('getMigrationsInfos') ->willReturn(['name' => 'value']); - $input->expects($this->once()) + $input->expects(self::once()) ->method('getOption') ->with('show-versions') ->willReturn(true); @@ -50,89 +50,89 @@ public function testExecute() : void $version1 = $this->createMock(Version::class); $migration1 = $this->createMock(AbstractMigration::class); - $version1->expects($this->once()) + $version1->expects(self::once()) ->method('getVersion') ->willReturn('1'); - $version1->expects($this->once()) + $version1->expects(self::once()) ->method('getMigration') ->willReturn($migration1); - $version1->expects($this->once()) + $version1->expects(self::once()) ->method('isMigrated') ->willReturn(true); $executedAt = new DateTimeImmutable('2018-05-16 11:14:40'); - $version1->expects($this->once()) + $version1->expects(self::once()) ->method('getExecutedAt') ->willReturn($executedAt); - $migration1->expects($this->once()) + $migration1->expects(self::once()) ->method('getDescription') ->willReturn('Test description.'); $version2 = $this->createMock(Version::class); $migration2 = $this->createMock(AbstractMigration::class); - $version2->expects($this->once()) + $version2->expects(self::once()) ->method('getVersion') ->willReturn('2'); - $version2->expects($this->once()) + $version2->expects(self::once()) ->method('getMigration') ->willReturn($migration2); - $version2->expects($this->once()) + $version2->expects(self::once()) ->method('isMigrated') ->willReturn(false); - $version2->expects($this->once()) + $version2->expects(self::once()) ->method('getExecutedAt') ->willReturn(null); - $migration2->expects($this->once()) + $migration2->expects(self::once()) ->method('getDescription') ->willReturn('Test description.'); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigrations') ->willReturn([$version1, $version2]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['1234']); - $this->configuration->expects($this->at(0)) + $this->configuration->expects(self::at(0)) ->method('getDateTime') ->with('1234') ->willReturn('123456789'); - $output->expects($this->at(0)) + $output->expects(self::at(0)) ->method('writeln') ->with("\n == Configuration\n"); - $output->expects($this->at(1)) + $output->expects(self::at(1)) ->method('writeln') ->with(' >> name: value'); - $output->expects($this->at(2)) + $output->expects(self::at(2)) ->method('writeln') ->with("\n == Available Migration Versions\n"); - $output->expects($this->at(3)) + $output->expects(self::at(3)) ->method('writeln') ->with(' >> (1) migrated (executed at 2018-05-16 11:14:40) Test description.'); - $output->expects($this->at(4)) + $output->expects(self::at(4)) ->method('writeln') ->with(' >> (2) not migrated Test description.'); - $output->expects($this->at(5)) + $output->expects(self::at(5)) ->method('writeln') ->with("\n == Previously Executed Unavailable Migration Versions\n"); - $output->expects($this->at(6)) + $output->expects(self::at(6)) ->method('writeln') ->with(' >> 123456789 (1234)'); @@ -146,7 +146,7 @@ protected function setUp() : void $this->migrationRepository = $this->createMock(MigrationRepository::class); $this->migrationStatusInfosHelper = $this->createMock(MigrationStatusInfosHelper::class); - $this->dependencyFactory->expects($this->once()) + $this->dependencyFactory->expects(self::once()) ->method('getMigrationStatusInfosHelper') ->willReturn($this->migrationStatusInfosHelper); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php index 7275e593e5..c80bc777a2 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php @@ -45,7 +45,7 @@ public function testIsUpToDate(array $migrations, array $migratedVersions, int $ $output = $this->createMock(OutputInterface::class); - $output->expects($this->once()) + $output->expects(self::once()) ->method('writeln'); $actual = $this->upToDateCommand->execute(new ArrayInput([]), $output); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php index 83ae396ac8..51e76dc39a 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php @@ -30,7 +30,7 @@ public function testGetConnection() : void $helperSet = $this->createMock(HelperSet::class); $connection = $this->createMock(Connection::class); - $this->connectionConfigurationChainLoader->expects($this->once()) + $this->connectionConfigurationChainLoader->expects(self::once()) ->method('chosen') ->wilLReturn($connection); @@ -50,7 +50,7 @@ protected function setUp() : void ConnectionLoaderInterface::class ); - $this->connectionLoader->expects($this->once()) + $this->connectionLoader->expects(self::once()) ->method('createConnectionConfigurationChainLoader') ->willReturn($this->connectionConfigurationChainLoader); } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php index 44037d64e7..513230f8bb 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php @@ -30,7 +30,7 @@ public function testRun() : void ConsoleRunnerStub::$application = $application; - $application->expects($this->once()) + $application->expects(self::once()) ->method('run'); ConsoleRunnerStub::run($helperSet, []); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php index 3f45de9dbf..a77fc28256 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php @@ -72,7 +72,7 @@ protected function getConfigurationHelperLoadsASpecificFormat( $this->input->method('getOption') ->with('configuration') - ->will($this->returnValue(null)); + ->will(self::returnValue(null)); $configurationHelper = new ConfigurationHelper($this->getSqliteConnection()); $configfileLoaded = $configurationHelper->getMigrationConfig($this->input); @@ -87,7 +87,7 @@ public function testConfigurationHelperLoadsPhpArrayFormatFromCommandLine() : vo { $this->input->method('getOption') ->with('configuration') - ->will($this->returnValue(__DIR__ . '/files/config.php')); + ->will(self::returnValue(__DIR__ . '/files/config.php')); $configurationHelper = new ConfigurationHelper($this->getSqliteConnection()); $migrationConfig = $configurationHelper->getMigrationConfig($this->input); @@ -100,7 +100,7 @@ public function testConfigurationHelperLoadsJsonFormatFromCommandLine() : void { $this->input->method('getOption') ->with('configuration') - ->will($this->returnValue(__DIR__ . '/files/config.json')); + ->will(self::returnValue(__DIR__ . '/files/config.json')); $configurationHelper = new ConfigurationHelper($this->getSqliteConnection()); $migrationConfig = $configurationHelper->getMigrationConfig($this->input); @@ -116,7 +116,7 @@ public function testConfigurationHelperFailsToLoadOtherFormat() : void { $this->input->method('getOption') ->with('configuration') - ->will($this->returnValue('testconfig.wrong')); + ->will(self::returnValue('testconfig.wrong')); $configurationHelper = new ConfigurationHelper($this->getSqliteConnection()); @@ -130,7 +130,7 @@ public function testConfigurationHelperWithoutConfigurationFromSetterAndWithoutO { $this->input->method('getOption') ->with('configuration') - ->will($this->returnValue(null)); + ->will(self::returnValue(null)); $configurationHelper = new ConfigurationHelper($this->connection, null); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php index c880f45c47..39b5c08cca 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php @@ -27,39 +27,39 @@ class MigrationStatusInfosHelperTest extends TestCase public function testGetMigrationsInfos() : void { - $this->driver->expects($this->once()) + $this->driver->expects(self::once()) ->method('getName') ->willReturn('pdo_mysql'); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('getHost') ->willReturn('localhost'); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('getDatabase') ->willReturn('dbname'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsTableName') ->willReturn('table_name'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsColumnName') ->willReturn('column_name'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsNamespace') ->willReturn('Doctrine'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getMigrationsDirectory') ->willReturn('/path/to/migrations'); - $this->configuration->expects($this->any()) + $this->configuration->expects(self::any()) ->method('resolveVersionAlias') ->willReturn('001'); - $this->configuration->expects($this->any()) + $this->configuration->expects(self::any()) ->method('getDateTime') ->willReturn('2017-09-01 01:01:01'); @@ -95,15 +95,15 @@ protected function setUp() : void $this->connection = $this->createMock(Connection::class); $this->driver = $this->createMock(Driver::class); - $this->configuration->expects($this->any()) + $this->configuration->expects(self::any()) ->method('getConnection') ->willReturn($this->connection); - $this->connection->expects($this->any()) + $this->connection->expects(self::any()) ->method('getDriver') ->willReturn($this->driver); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigratedVersions') ->willReturn([ '001', @@ -111,7 +111,7 @@ protected function setUp() : void '003', ]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getAvailableVersions') ->willReturn([ '001', @@ -119,11 +119,11 @@ protected function setUp() : void '004', ]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getNewVersions') ->willReturn(['004']); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getExecutedUnavailableMigrations') ->willReturn(['001']); diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php index 734f7560ec..50e3aedb22 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php @@ -62,11 +62,11 @@ public function testGetDBALTable() : void { $schemaConfig = $this->createMock(SchemaConfig::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('createSchemaConfig') ->willReturn($schemaConfig); - $schemaConfig->expects($this->once()) + $schemaConfig->expects(self::once()) ->method('getDefaultTableOptions') ->willReturn(['test_option' => true]); @@ -88,11 +88,11 @@ public function testGetNewDBALTable() : void { $schemaConfig = $this->createMock(SchemaConfig::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('createSchemaConfig') ->willReturn($schemaConfig); - $schemaConfig->expects($this->once()) + $schemaConfig->expects(self::once()) ->method('getDefaultTableOptions') ->willReturn(['test_option' => true]); diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php index 989c21a456..532da5ff9c 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php @@ -35,18 +35,18 @@ class TableManipulatorTest extends TestCase public function testCreateMigrationTableAlreadyCreated() : void { - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('validate'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('isDryRun') ->willReturn(false); - $this->migrationTableStatus->expects($this->once()) + $this->migrationTableStatus->expects(self::once()) ->method('isCreated') ->willReturn(true); - $this->migrationTableStatus->expects($this->once()) + $this->migrationTableStatus->expects(self::once()) ->method('isUpToDate') ->willReturn(true); @@ -66,25 +66,25 @@ public function testCreateMigrationTableNotUpToDate() : void ->setMethods(['createSchema']) ->getMock(); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('validate'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('isDryRun') ->willReturn(false); - $this->migrationTableStatus->expects($this->once()) + $this->migrationTableStatus->expects(self::once()) ->method('isCreated') ->willReturn(true); - $this->migrationTableStatus->expects($this->once()) + $this->migrationTableStatus->expects(self::once()) ->method('isUpToDate') ->willReturn(false); - $this->migrationTableUpdater->expects($this->once()) + $this->migrationTableUpdater->expects(self::once()) ->method('updateMigrationTable'); - $this->migrationTableStatus->expects($this->once()) + $this->migrationTableStatus->expects(self::once()) ->method('setUpToDate') ->with(true); @@ -93,24 +93,24 @@ public function testCreateMigrationTableNotUpToDate() : void public function testCreateMigrationTable() : void { - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('validate'); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('isDryRun') ->willReturn(false); - $this->migrationTableStatus->expects($this->once()) + $this->migrationTableStatus->expects(self::once()) ->method('isCreated') ->willReturn(false); $table = $this->createMock(Table::class); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getNewDBALTable') ->willReturn($table); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('createTable') ->with($table); diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php index 55e0d08e0c..d422ad8786 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php @@ -30,11 +30,11 @@ public function testSetCreated() : void public function testIsCreatedTrue() : void { - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getName') ->willReturn('table_name'); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('tablesExist') ->with(['table_name']) ->willReturn(true); @@ -44,11 +44,11 @@ public function testIsCreatedTrue() : void public function testIsCreatedFalse() : void { - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getName') ->willReturn('table_name'); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('tablesExist') ->with(['table_name']) ->willReturn(false); @@ -65,30 +65,30 @@ public function testSetUpToDate() : void public function testIsUpToDateTrue() : void { - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getName') ->willReturn('table_name'); $table = $this->createMock(Table::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('listTableDetails') ->with('table_name') ->willReturn($table); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getColumnNames') ->willReturn([ 'version', 'executed_at', ]); - $table->expects($this->at(0)) + $table->expects(self::at(0)) ->method('hasColumn') ->with('version') ->willReturn(true); - $table->expects($this->at(1)) + $table->expects(self::at(1)) ->method('hasColumn') ->with('executed_at') ->willReturn(true); @@ -98,30 +98,30 @@ public function testIsUpToDateTrue() : void public function testIsUpToDateFalse() : void { - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getName') ->willReturn('table_name'); $table = $this->createMock(Table::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('listTableDetails') ->with('table_name') ->willReturn($table); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getColumnNames') ->willReturn([ 'version', 'executed_at', ]); - $table->expects($this->at(0)) + $table->expects(self::at(0)) ->method('hasColumn') ->with('version') ->willReturn(true); - $table->expects($this->at(1)) + $table->expects(self::at(1)) ->method('hasColumn') ->with('executed_at') ->willReturn(false); diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php index 271b4946b1..dd67ec46cb 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php @@ -36,11 +36,11 @@ class TableUpdaterTest extends TestCase public function testUpdateMigrationTable() : void { - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getName') ->willReturn('table_name'); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getColumnNames') ->willReturn([ 'version', @@ -49,7 +49,7 @@ public function testUpdateMigrationTable() : void $table = $this->createMock(Table::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('listTableDetails') ->willReturn($table); @@ -64,7 +64,7 @@ public function testUpdateMigrationTable() : void Type::getType('datetime_immutable') ); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('createDBALTable') ->with([ $versionColumn, @@ -72,7 +72,7 @@ public function testUpdateMigrationTable() : void ]) ->willReturn($table); - $table->expects($this->any()) + $table->expects(self::any()) ->method('getColumns') ->willReturn([ $versionColumn, @@ -82,27 +82,27 @@ public function testUpdateMigrationTable() : void $fromSchema = $this->createMock(Schema::class); $toSchema = $this->createMock(Schema::class); - $this->migrationTableUpdater->expects($this->at(0)) + $this->migrationTableUpdater->expects(self::at(0)) ->method('createSchema') ->willReturn($fromSchema); - $this->migrationTableUpdater->expects($this->at(1)) + $this->migrationTableUpdater->expects(self::at(1)) ->method('createSchema') ->willReturn($toSchema); - $fromSchema->expects($this->once()) + $fromSchema->expects(self::once()) ->method('getMigrateToSql') ->with($toSchema, $this->platform) ->willReturn(['ALTER TABLE table_name ADD COLUMN executed_at DATETIME DEFAULT NULL']); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('beginTransaction'); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('executeQuery') ->with('ALTER TABLE table_name ADD COLUMN executed_at DATETIME DEFAULT NULL'); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('commit'); $this->migrationTableUpdater->updateMigrationTable(); @@ -113,11 +113,11 @@ public function testUpdateMigrationTableRollback() : void $this->expectException(Throwable::class); $this->expectExceptionMessage('Rolling back.'); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getName') ->willReturn('table_name'); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('getColumnNames') ->willReturn([ 'version', @@ -126,7 +126,7 @@ public function testUpdateMigrationTableRollback() : void $table = $this->createMock(Table::class); - $this->schemaManager->expects($this->once()) + $this->schemaManager->expects(self::once()) ->method('listTableDetails') ->willReturn($table); @@ -141,7 +141,7 @@ public function testUpdateMigrationTableRollback() : void Type::getType('datetime_immutable') ); - $this->migrationTable->expects($this->once()) + $this->migrationTable->expects(self::once()) ->method('createDBALTable') ->with([ $versionColumn, @@ -149,7 +149,7 @@ public function testUpdateMigrationTableRollback() : void ]) ->willReturn($table); - $table->expects($this->any()) + $table->expects(self::any()) ->method('getColumns') ->willReturn([ $versionColumn, @@ -159,28 +159,28 @@ public function testUpdateMigrationTableRollback() : void $fromSchema = $this->createMock(Schema::class); $toSchema = $this->createMock(Schema::class); - $this->migrationTableUpdater->expects($this->at(0)) + $this->migrationTableUpdater->expects(self::at(0)) ->method('createSchema') ->willReturn($fromSchema); - $this->migrationTableUpdater->expects($this->at(1)) + $this->migrationTableUpdater->expects(self::at(1)) ->method('createSchema') ->willReturn($toSchema); - $fromSchema->expects($this->once()) + $fromSchema->expects(self::once()) ->method('getMigrateToSql') ->with($toSchema, $this->platform) ->willReturn(['ALTER TABLE table_name ADD COLUMN executed_at DATETIME DEFAULT NULL']); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('beginTransaction'); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('executeQuery') ->with('ALTER TABLE table_name ADD COLUMN executed_at DATETIME DEFAULT NULL') ->willThrowException(new Exception('Rolling back.')); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('rollback'); $this->migrationTableUpdater->updateMigrationTable(); diff --git a/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php b/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php index bdc692ebb8..db089143b7 100644 --- a/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php @@ -25,13 +25,13 @@ public function testResolveVersionAlias( ?string $expectedMethod, ?string $expectedArgument ) : void { - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('hasVersion') ->with($alias) ->willReturn(false); if ($expectedMethod !== null) { - $expectation = $this->migrationRepository->expects($this->once()) + $expectation = $this->migrationRepository->expects(self::once()) ->method($expectedMethod) ->willReturn($expectedVersion); @@ -61,7 +61,7 @@ public function getAliases() : array public function testResolveVersionAliasHasVersion() : void { - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('hasVersion') ->with('test') ->willReturn(true); diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php index 8a1a1c3f06..77618289f1 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -64,48 +64,48 @@ public function testExecuteUp() : void { $platform = $this->createMock(AbstractPlatform::class); - $this->connection->expects($this->once()) + $this->connection->expects(self::once()) ->method('getDatabasePlatform') ->willReturn($platform); $stopwatchEvent = $this->createMock(StopwatchEvent::class); - $this->stopwatch->expects($this->any()) + $this->stopwatch->expects(self::any()) ->method('start') ->willReturn($stopwatchEvent); - $stopwatchEvent->expects($this->any()) + $stopwatchEvent->expects(self::any()) ->method('stop'); - $stopwatchEvent->expects($this->any()) + $stopwatchEvent->expects(self::any()) ->method('getDuration') ->willReturn(100); - $stopwatchEvent->expects($this->any()) + $stopwatchEvent->expects(self::any()) ->method('getMemory') ->willReturn(100); - $this->outputWriter->expects($this->at(0)) + $this->outputWriter->expects(self::at(0)) ->method('write') ->with("\n ++ migrating 001\n"); - $this->outputWriter->expects($this->at(1)) + $this->outputWriter->expects(self::at(1)) ->method('write') ->with(' -> SELECT 1'); - $this->outputWriter->expects($this->at(2)) + $this->outputWriter->expects(self::at(2)) ->method('write') ->with(' 100ms'); - $this->outputWriter->expects($this->at(3)) + $this->outputWriter->expects(self::at(3)) ->method('write') ->with(' -> SELECT 2'); - $this->outputWriter->expects($this->at(4)) + $this->outputWriter->expects(self::at(4)) ->method('write') ->with(' 100ms'); - $this->outputWriter->expects($this->at(5)) + $this->outputWriter->expects(self::at(5)) ->method('write') ->with("\n ++ migrated (took 100ms, used 100 memory)"); @@ -135,42 +135,42 @@ public function testExecuteDown() : void { $stopwatchEvent = $this->createMock(StopwatchEvent::class); - $this->stopwatch->expects($this->any()) + $this->stopwatch->expects(self::any()) ->method('start') ->willReturn($stopwatchEvent); - $stopwatchEvent->expects($this->any()) + $stopwatchEvent->expects(self::any()) ->method('stop'); - $stopwatchEvent->expects($this->any()) + $stopwatchEvent->expects(self::any()) ->method('getDuration') ->willReturn(100); - $stopwatchEvent->expects($this->any()) + $stopwatchEvent->expects(self::any()) ->method('getMemory') ->willReturn(100); - $this->outputWriter->expects($this->at(0)) + $this->outputWriter->expects(self::at(0)) ->method('write') ->with("\n -- reverting 001\n"); - $this->outputWriter->expects($this->at(1)) + $this->outputWriter->expects(self::at(1)) ->method('write') ->with(' -> SELECT 3'); - $this->outputWriter->expects($this->at(2)) + $this->outputWriter->expects(self::at(2)) ->method('write') ->with(' 100ms'); - $this->outputWriter->expects($this->at(3)) + $this->outputWriter->expects(self::at(3)) ->method('write') ->with(' -> SELECT 4'); - $this->outputWriter->expects($this->at(4)) + $this->outputWriter->expects(self::at(4)) ->method('write') ->with(' 100ms'); - $this->outputWriter->expects($this->at(5)) + $this->outputWriter->expects(self::at(5)) ->method('write') ->with("\n -- reverted (took 100ms, used 100 memory)"); @@ -214,7 +214,7 @@ protected function setUp() : void $this->stopwatch ); - $this->configuration->expects($this->any()) + $this->configuration->expects(self::any()) ->method('getConnection') ->willReturn($this->connection); diff --git a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php index e4a37850ec..3aa2c8a236 100644 --- a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php @@ -197,7 +197,7 @@ public function testWriteSqlFile(string $path, string $direction, array $getSqlR $outputWriter = $this->createMock(OutputWriter::class); $queryWriter = $this->createMock(QueryWriter::class); - $outputWriter->expects($this->atLeastOnce()) + $outputWriter->expects(self::atLeastOnce()) ->method('write'); /** @var Configuration|PHPUnit_Framework_MockObject_MockObject $config */ @@ -223,7 +223,7 @@ public function testWriteSqlFile(string $path, string $direction, array $getSqlR $versionExecutionResult = new ExecutionResult($getSqlReturn); - $version->expects($this->once()) + $version->expects(self::once()) ->method('execute') ->with($direction) ->willReturn($versionExecutionResult); From bf980f3dc2ff16badb7fda9cb03a3b7442936e87 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 12 Sep 2018 15:15:48 +0200 Subject: [PATCH 2/4] Enable PHPStan in tests/ --- phpstan.neon.dist | 13 +++++- .../Migrations/Tests/BoxPharCompileTest.php | 2 +- .../AbstractFileConfigurationTest.php | 2 +- .../ConnectionConfigurationLoaderTest.php | 6 ++- .../Migrations/Tests/ConfigurationTest.php | 6 +-- .../Listeners/AutoCommitListenerTest.php | 3 +- .../Migrations/Tests/FileQueryWriterTest.php | 2 +- .../Migrations/Tests/Functional/CliTest.php | 3 +- .../Tests/Functional/FunctionalTest.php | 2 +- .../Tests/Generator/DiffGeneratorTest.php | 18 ++++---- .../Tests/Generator/FileBuilderTest.php | 3 +- .../Tests/Generator/GeneratorTest.php | 5 ++- .../Tests/Generator/SqlGeneratorTest.php | 5 ++- .../Tests/MigrationPlanCalculatorTest.php | 3 +- .../Tests/MigrationRepositoryTest.php | 9 ++-- .../Migrations/Tests/MigrationTestCase.php | 2 +- .../Migrations/Tests/MigratorTest.php | 12 ++--- .../Migrations/Tests/OutputWriterTest.php | 4 +- .../Doctrine/Migrations/Tests/RollupTest.php | 9 ++-- .../Migrations/Tests/SchemaDumperTest.php | 9 ++-- .../Tools/Console/Command/CommandTestCase.php | 2 +- .../Tools/Console/Command/DiffCommandTest.php | 7 +-- .../Console/Command/DumpSchemaCommandTest.php | 11 ++--- .../Console/Command/ExecuteCommandTest.php | 5 ++- .../Console/Command/GenerateCommandTest.php | 9 ++-- .../Console/Command/MigrateCommandTest.php | 10 +++-- .../Console/Command/MigrationVersionTest.php | 3 +- .../Console/Command/RollupCommandTest.php | 7 +-- .../Console/Command/StatusCommandTest.php | 9 ++-- .../Console/Command/UpToDateCommandTest.php | 3 +- .../Tools/Console/ConnectionLoaderTest.php | 5 ++- .../Tests/Tools/Console/ConsoleRunnerTest.php | 5 ++- .../Helper/MigrationStatusInfosHelperTest.php | 10 +++-- .../Tests/Tracking/TableDefinitionTest.php | 3 +- .../Tests/Tracking/TableManipulatorTest.php | 11 ++--- .../Tests/Tracking/TableStatusTest.php | 11 ++--- .../Tests/Tracking/TableUpdaterTest.php | 11 ++--- .../Tests/Version/AliasResolverTest.php | 5 ++- .../Tests/Version/ExecutionResultTest.php | 3 ++ .../Migrations/Tests/Version/ExecutorTest.php | 15 ++++--- .../Migrations/Tests/Version/FactoryTest.php | 3 +- .../Migrations/Tests/Version/VersionTest.php | 45 +++++++++++++------ 42 files changed, 189 insertions(+), 122 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6a7ab1e9ee..febed60215 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,13 +2,22 @@ parameters: level: 7 paths: - %currentWorkingDirectory%/lib + - %currentWorkingDirectory%/tests + autoload_directories: + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Finder/_features + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Finder/_files + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Finder/_regression + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Functional/_files + autoload_files: + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php ignoreErrors: # Ignore proxy manager magic - '~ProxyManager\\Proxy\\VirtualProxyInterface~' - - '~Parameter #1 \$files of method Doctrine\\Migrations\\Finder\\Finder::loadMigrationClasses\(\) expects array, array given~' -#' + - '~^Parameter #1 \$files of method Doctrine\\Migrations\\Finder\\Finder::loadMigrationClasses\(\) expects array, array given\.\z~' + - '~^Class Doctrine\\Migrations\\Tests\\DoesNotExistAtAll not found\.\z~' includes: - vendor/phpstan/phpstan-deprecation-rules/rules.neon - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php b/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php index b4794ff309..cfb29ed1e5 100644 --- a/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php +++ b/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php @@ -20,7 +20,7 @@ public function testCompile() : void $boxPharPath = __DIR__ . '/../../../../box.phar'; if (! file_exists($boxPharPath)) { - $this->markTestSkipped('Download box with the ./download-box.sh shell script.'); + self::markTestSkipped('Download box with the ./download-box.sh shell script.'); } $boxPharPath = realpath($boxPharPath); diff --git a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php index ae21f453c9..a31fd74b2d 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php @@ -17,7 +17,7 @@ class AbstractFileConfigurationTest extends TestCase /** @var Connection */ private $connection; - /** @var AbstractFileConfiguration */ + /** @var TestAbstractFileConfiguration */ private $fileConfiguration; public function testLoadChecksCurrentWorkingDirectory() : void diff --git a/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php b/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php index bf30f2d2cb..ea0cea4677 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/Connection/Loader/ConnectionConfigurationLoaderTest.php @@ -7,13 +7,17 @@ use Doctrine\DBAL\Connection; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Configuration\Connection\Loader\ConnectionConfigurationLoader; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; final class ConnectionConfigurationLoaderTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; + /** @var ConnectionConfigurationLoader */ + private $connectionConfigurationLoader; + public function testChosenReturnsNull() : void { $connectionConfigurationLoader = new ConnectionConfigurationLoader(); diff --git a/tests/Doctrine/Migrations/Tests/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/ConfigurationTest.php index cac57e3523..ec173e46ea 100644 --- a/tests/Doctrine/Migrations/Tests/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/ConfigurationTest.php @@ -159,8 +159,8 @@ public function testRegisterDuplicateVersion() : void $config->registerMigration('1234', Version1Test::class); - $this->expectException( - MigrationException::class, + $this->expectException(MigrationException::class); + $this->expectExceptionMessage( 'Migration version 1234 already registered with class Doctrine\Migrations\Version' ); $config->registerMigration('1234', Version1Test::class); @@ -455,7 +455,7 @@ public function testSetCustomTemplateShould(?string $template) : void } /** - * @return string|null[][] + * @return string[][]|null[][] */ public function validCustomTemplates() : array { diff --git a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php index e5aa360fa6..c03df1851c 100644 --- a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php +++ b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php @@ -9,10 +9,11 @@ use Doctrine\Migrations\Event\Listeners\AutoCommitListener; use Doctrine\Migrations\Event\MigrationsEventArgs; use Doctrine\Migrations\Tests\MigrationTestCase; +use PHPUnit\Framework\MockObject\MockObject; class AutoCommitListenerTest extends MigrationTestCase { - /** @var Connection */ + /** @var Connection|MockObject */ private $conn; /** @var AutoCommitListener */ diff --git a/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php b/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php index 5e62fe2362..782004e122 100644 --- a/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php +++ b/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php @@ -92,7 +92,7 @@ public function writeProvider() : array $outputWriter->expects(self::atLeastOnce()) ->method('write') - ->with($this->isType('string')); + ->with(self::isType('string')); return [ [__DIR__, Direction::UP, ['1' => ['SHOW DATABASES']], $outputWriter], diff --git a/tests/Doctrine/Migrations/Tests/Functional/CliTest.php b/tests/Doctrine/Migrations/Tests/Functional/CliTest.php index faf69700e5..e75905cc61 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/CliTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/CliTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Migrations\Tests\Functional; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\Migrations\AbstractMigration; @@ -299,7 +300,7 @@ protected function getSchema() : Schema } /** - * @return array|string[] + * @return string[] */ private function findMigrations() : array { diff --git a/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php b/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php index 33c46f6f16..8f9478cab9 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php @@ -524,7 +524,7 @@ public function testMigrationExecutedAt() : void } /** - * @return Connection|Configuration[] + * @return object[] [Connection, Configuration] */ private static function fileConnectionAndConfig() : array { diff --git a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php index 6f1abaf725..54f1748e7f 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php @@ -13,26 +13,27 @@ use Doctrine\Migrations\Generator\Generator; use Doctrine\Migrations\Generator\SqlGenerator; use Doctrine\Migrations\Provider\SchemaProviderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class DiffGeneratorTest extends TestCase { - /** @var DBALConfiguration */ + /** @var DBALConfiguration|MockObject */ private $dbalConfiguration; - /** @var AbstractSchemaManager */ + /** @var AbstractSchemaManager|MockObject */ private $schemaManager; - /** @var SchemaProviderInterface */ + /** @var SchemaProviderInterface|MockObject */ private $schemaProvider; - /** @var AbstractPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var Generator */ + /** @var Generator|MockObject */ private $migrationGenerator; - /** @var SqlGenerator */ + /** @var SqlGenerator|MockObject */ private $migrationSqlGenerator; /** @var DiffGenerator */ @@ -122,16 +123,13 @@ protected function setUp() : void $this->platform = $this->createMock(AbstractPlatform::class); $this->migrationGenerator = $this->createMock(Generator::class); $this->migrationSqlGenerator = $this->createMock(SqlGenerator::class); - $this->migrationDiffGenerator = $this->createMock(DiffGenerator::class); - $this->migrationDiffGenerator = new DiffGenerator( $this->dbalConfiguration, $this->schemaManager, $this->schemaProvider, $this->platform, $this->migrationGenerator, - $this->migrationSqlGenerator, - $this->migrationDiffGenerator + $this->migrationSqlGenerator ); } } diff --git a/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php b/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php index cf9f78dc4b..074733777b 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/FileBuilderTest.php @@ -8,11 +8,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Migrations\Generator\FileBuilder; use Doctrine\Migrations\Version\Direction; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FileBuilderTest extends TestCase { - /** @var AbstractPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var FileBuilder */ diff --git a/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php index 7281360d9f..b887efd0f8 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/GeneratorTest.php @@ -7,6 +7,7 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Generator\Generator; use InvalidArgumentException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function class_exists; use function file_get_contents; @@ -17,7 +18,7 @@ final class GeneratorTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; /** @var Generator */ @@ -98,7 +99,7 @@ public function testCustomTemplateThrowsInvalidArgumentExceptionWhenTemplateEmpt $this->migrationGenerator->generateMigration('1234'); - unlink($path); + unlink($customTemplate); } protected function setUp() : void diff --git a/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php index 3144e92d47..4dc9a5ba5e 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/SqlGeneratorTest.php @@ -7,16 +7,17 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Generator\SqlGenerator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use SqlFormatter; use function sprintf; final class SqlGeneratorTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var AbstractPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; /** @var SqlGenerator */ diff --git a/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php b/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php index a4a8d2ef96..3a00221628 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php +++ b/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php @@ -8,11 +8,12 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Version\Direction; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; final class MigrationPlanCalculatorTest extends TestCase { - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; /** @var MigrationPlanCalculator */ diff --git a/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php b/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php index e9967984f6..2cb5fd6db9 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php +++ b/tests/Doctrine/Migrations/Tests/MigrationRepositoryTest.php @@ -11,20 +11,21 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Version\Factory; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class MigrationRepositoryTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var Connection */ + /** @var Connection|MockObject */ private $connection; - /** @var MigrationFinder */ + /** @var MigrationFinder|MockObject */ private $migrationFinder; - /** @var Factory */ + /** @var Factory|MockObject */ private $versionFactory; /** @var MigrationRepository */ diff --git a/tests/Doctrine/Migrations/Tests/MigrationTestCase.php b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php index 758219f873..7386d3b9b1 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationTestCase.php +++ b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php @@ -76,7 +76,7 @@ public function getInputStream(string $input) protected function getOutputWriter() : OutputWriter { - if (! $this->outputWriter) { + if ($this->outputWriter === null) { $this->output = $this->getOutputStream(); $output = $this->output; $this->outputWriter = new OutputWriter(static function ($message) use ($output) { diff --git a/tests/Doctrine/Migrations/Tests/MigratorTest.php b/tests/Doctrine/Migrations/Tests/MigratorTest.php index 4accaf47c9..264c5459af 100644 --- a/tests/Doctrine/Migrations/Tests/MigratorTest.php +++ b/tests/Doctrine/Migrations/Tests/MigratorTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Migrations\Tests; -use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\Connection; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Exception\MigrationException; @@ -18,7 +18,7 @@ use Doctrine\Migrations\Tests\Stub\Functional\MigrationThrowsError; use Doctrine\Migrations\Version\Direction; use PHPUnit\Framework\Constraint\RegularExpression; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Output\StreamOutput; use Throwable; use const DIRECTORY_SEPARATOR; @@ -134,7 +134,7 @@ public function testMigrateWithNoMigrationsDontThrowsExceptionIfContiniousIntegr */ public function testGetSql(?string $to) : void { - /** @var Migration|PHPUnit_Framework_MockObject_MockObject $migration */ + /** @var Migrator|MockObject $migration */ $migration = $this->getMockBuilder(Migrator::class) ->disableOriginalConstructor() ->setMethods(['migrate']) @@ -152,7 +152,7 @@ public function testGetSql(?string $to) : void self::assertSame($expected, $result); } - /** @return string|null[] */ + /** @return string[]|null[] */ public function getSqlProvider() : array { return [ @@ -207,10 +207,10 @@ public function testWriteSqlFile(string $path, string $from, ?string $to, array if ($to === null) { // this will always just test the "up" direction $config->method('getLatestVersion') - ->willReturn($from + 1); + ->willReturn((int) $from + 1); } - /** @var Migration|PHPUnit_Framework_MockObject_MockObject $migration */ + /** @var Migrator|MockObject $migration */ $migration = $this->getMockBuilder(Migrator::class) ->setConstructorArgs($this->getMigratorConstructorArgs($config)) ->setMethods(['getSql']) diff --git a/tests/Doctrine/Migrations/Tests/OutputWriterTest.php b/tests/Doctrine/Migrations/Tests/OutputWriterTest.php index c5d12eb1b3..1b53ceb7e5 100644 --- a/tests/Doctrine/Migrations/Tests/OutputWriterTest.php +++ b/tests/Doctrine/Migrations/Tests/OutputWriterTest.php @@ -19,7 +19,9 @@ public function testDefaultCallback() : void { $outputWriter = new OutputWriter(); - self::assertNull($outputWriter->write('test message')); + $outputWriter->write('test message'); + + self::markTestIncomplete('Does not perform any real assertion.'); } public function testWrite() : void diff --git a/tests/Doctrine/Migrations/Tests/RollupTest.php b/tests/Doctrine/Migrations/Tests/RollupTest.php index c828b37815..d55d84c351 100644 --- a/tests/Doctrine/Migrations/Tests/RollupTest.php +++ b/tests/Doctrine/Migrations/Tests/RollupTest.php @@ -9,18 +9,19 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Rollup; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; class RollupTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var Connection */ + /** @var Connection|MockObject */ private $connection; - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; /** @var Rollup */ @@ -79,7 +80,7 @@ public function testRollup() : void $version1->expects(self::once()) ->method('markMigrated'); - $this->assertSame($version1, $this->rollup->rollup()); + self::assertSame($version1, $this->rollup->rollup()); } protected function setUp() : void diff --git a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php index 3af800d9c1..1781daaa85 100644 --- a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php +++ b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php @@ -11,21 +11,22 @@ use Doctrine\Migrations\Generator\Generator; use Doctrine\Migrations\Generator\SqlGenerator; use Doctrine\Migrations\SchemaDumper; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; class SchemaDumperTest extends TestCase { - /** @var AbstractPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var AbstractSchemaManager */ + /** @var AbstractSchemaManager|MockObject */ private $schemaManager; - /** @var Generator */ + /** @var Generator|MockObject */ private $migrationGenerator; - /** @var SqlGenerator */ + /** @var SqlGenerator|MockObject */ private $migrationSqlGenerator; /** @var SchemaDumper */ diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/CommandTestCase.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/CommandTestCase.php index 613eccb0cf..7fb0e355d9 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/CommandTestCase.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/CommandTestCase.php @@ -54,7 +54,7 @@ protected function createCommandTester() : CommandTester * @param mixed[] $args * @param mixed[] $options * - * @return CommandTester|int[] + * @return mixed[] [CommandTester, int] */ protected function executeCommand(array $args, array $options = []) : array { diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php index f3c4b9df39..3e9b43a95b 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php @@ -7,19 +7,20 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Generator\DiffGenerator; use Doctrine\Migrations\Tools\Console\Command\DiffCommand; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class DiffCommandTest extends TestCase { - /** @var DiffGenerator */ + /** @var DiffGenerator|MockObject */ private $migrationDiffGenerator; - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var DiffCommand */ + /** @var DiffCommand|MockObject */ private $diffCommand; public function testExecute() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php index 44edb8dbee..96e2f8e827 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php @@ -10,6 +10,7 @@ use Doctrine\Migrations\SchemaDumper; use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; use Symfony\Component\Console\Input\InputInterface; @@ -17,19 +18,19 @@ final class DumpSchemaCommandTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var DependencyFactory */ + /** @var DependencyFactory|MockObject */ private $dependencyFactory; - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; - /** @var SchemaDumper */ + /** @var SchemaDumper|MockObject */ private $schemaDumper; - /** @var GenerateCommand */ + /** @var DumpSchemaCommand|MockObject */ private $dumpSchemaCommand; public function testExecuteThrowsRuntimeException() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php index c89bcfd02a..cfefee5e1e 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php @@ -7,6 +7,7 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -14,10 +15,10 @@ class ExecuteCommandTest extends TestCase { - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; - /** @var ExecuteCommand */ + /** @var ExecuteCommand|MockObject */ private $executeCommand; public function testWriteSqlCustomPath() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php index 4ab0551563..a73a08d340 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php @@ -8,22 +8,23 @@ use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Generator\Generator; use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class GenerateCommandTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var DependencyFactory */ + /** @var DependencyFactory|MockObject */ private $dependencyFactory; - /** @var Generator */ + /** @var Generator|MockObject */ private $migrationGenerator; - /** @var GenerateCommand */ + /** @var GenerateCommand|MockObject */ private $generateCommand; public function testExecute() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index dfcf3cba2a..daf9e93056 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -9,6 +9,7 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Migrator; use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,13 +17,16 @@ class MigrateCommandTest extends TestCase { - /** @var DependencyFactory */ + /** @var DependencyFactory|MockObject */ private $dependencyFactory; - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; - /** @var MigrateCommand */ + /** @var Configuration|MockObject */ + private $configuration; + + /** @var MigrateCommand|MockObject */ private $migrateCommand; public function testExecuteCouldNotResolveAlias() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php index 19eff144d9..1038480a0e 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationVersionTest.php @@ -9,12 +9,13 @@ use Doctrine\Migrations\Tests\Stub\Version1Test; use Doctrine\Migrations\Tools\Console\Command\VersionCommand; use InvalidArgumentException; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Tester\CommandTester; use function sys_get_temp_dir; class MigrationVersionTest extends MigrationTestCase { - /** @var VersionCommand */ + /** @var VersionCommand|MockObject */ private $command; /** @var Configuration */ diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php index 9f75197ad6..f448453ba2 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/RollupCommandTest.php @@ -8,19 +8,20 @@ use Doctrine\Migrations\Rollup; use Doctrine\Migrations\Tools\Console\Command\RollupCommand; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class RollupCommandTest extends TestCase { - /** @var DependencyFactory */ + /** @var DependencyFactory|MockObject */ private $dependencyFactory; - /** @var Rollup */ + /** @var Rollup|MockObject */ private $rollup; - /** @var RollupCommand */ + /** @var RollupCommand|MockObject */ private $rollupCommand; public function testExecute() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php index e4e27453eb..7ffeaa3dc7 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php @@ -12,22 +12,23 @@ use Doctrine\Migrations\Tools\Console\Command\StatusCommand; use Doctrine\Migrations\Tools\Console\Helper\MigrationStatusInfosHelper; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class StatusCommandTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var DependencyFactory */ + /** @var DependencyFactory|MockObject */ private $dependencyFactory; - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; - /** @var MigrationStatusInfosHelper */ + /** @var MigrationStatusInfosHelper|MockObject */ private $migrationStatusInfosHelper; /** @var StatusCommand */ diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php index c80bc777a2..27281459d1 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php @@ -7,13 +7,14 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; class UpToDateCommandTest extends TestCase { - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; /** @var UpToDateCommand */ diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php index 51e76dc39a..19e63b6888 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php @@ -9,16 +9,17 @@ use Doctrine\Migrations\Configuration\Connection\ConnectionLoaderInterface; use Doctrine\Migrations\Configuration\Connection\Loader\ConnectionConfigurationChainLoader; use Doctrine\Migrations\Tools\Console\ConnectionLoader; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Input\InputInterface; class ConnectionLoaderTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var ConnectionConfigurationChainLoader */ + /** @var ConnectionConfigurationChainLoader|MockObject */ private $connectionConfigurationChainLoader; /** @var ConnectionLoader */ diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php index 513230f8bb..abf6887278 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\HelperSet; /** @@ -128,7 +129,9 @@ class ConsoleRunnerStub extends ConsoleRunner /** @var Application|null */ public static $application; - /** @param AbstractCommand[] $commands */ + /** + * @param Command[] $commands + */ public static function createApplication(HelperSet $helperSet, array $commands = []) : Application { return static::$application; diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php index 39b5c08cca..ee9d515775 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php @@ -9,19 +9,23 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Tools\Console\Helper\MigrationStatusInfosHelper; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class MigrationStatusInfosHelperTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var Connection */ + /** @var Connection|MockObject */ private $connection; - /** @var Driver */ + /** @var Driver|MockObject */ private $driver; + /** @var MigrationRepository|MockObject */ + private $migrationRepository; + /** @var MigrationStatusInfosHelper */ private $migrationStatusInfosHelper; diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php index 50e3aedb22..6820a4acb8 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php @@ -7,11 +7,12 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\Migrations\Tracking\TableDefinition; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class TableDefinitionTest extends TestCase { - /** @var AbstractSchemaManager */ + /** @var AbstractSchemaManager|MockObject */ private $schemaManager; /** @var TableDefinition */ diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php index 532da5ff9c..95971e75de 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php @@ -11,23 +11,24 @@ use Doctrine\Migrations\Tracking\TableManipulator; use Doctrine\Migrations\Tracking\TableStatus; use Doctrine\Migrations\Tracking\TableUpdater; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class TableManipulatorTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var AbstractSchemaManager */ + /** @var AbstractSchemaManager|MockObject */ private $schemaManager; - /** @var TableDefinition */ + /** @var TableDefinition|MockObject */ private $migrationTable; - /** @var TableStatus */ + /** @var TableStatus|MockObject */ private $migrationTableStatus; - /** @var TableUpdater */ + /** @var TableUpdater|MockObject */ private $migrationTableUpdater; /** @var TableManipulator */ diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php index d422ad8786..67d393d92c 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php @@ -8,14 +8,15 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\Migrations\Tracking\TableDefinition; use Doctrine\Migrations\Tracking\TableStatus; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class TableStatusTest extends TestCase { - /** @var AbstractSchemaManager */ + /** @var AbstractSchemaManager|MockObject */ private $schemaManager; - /** @var TableDefinition */ + /** @var TableDefinition|MockObject */ private $migrationTable; /** @var TableStatus */ @@ -58,7 +59,7 @@ public function testIsCreatedFalse() : void public function testSetUpToDate() : void { - $this->migrationTableStatus->setUpTodate(true); + $this->migrationTableStatus->setUpToDate(true); self::assertTrue($this->migrationTableStatus->isUpToDate()); } @@ -93,7 +94,7 @@ public function testIsUpToDateTrue() : void ->with('executed_at') ->willReturn(true); - self::assertTrue($this->migrationTableStatus->isUpTodate()); + self::assertTrue($this->migrationTableStatus->isUpToDate()); } public function testIsUpToDateFalse() : void @@ -126,7 +127,7 @@ public function testIsUpToDateFalse() : void ->with('executed_at') ->willReturn(false); - self::assertFalse($this->migrationTableStatus->isUpTodate()); + self::assertFalse($this->migrationTableStatus->isUpToDate()); } protected function setUp() : void diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php index dd67ec46cb..45467f8a10 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php @@ -14,24 +14,25 @@ use Doctrine\Migrations\Tracking\TableDefinition; use Doctrine\Migrations\Tracking\TableUpdater; use Exception; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Throwable; class TableUpdaterTest extends TestCase { - /** @var Connection */ + /** @var Connection|MockObject */ private $connection; - /** @var AbstractSchemaManager */ + /** @var AbstractSchemaManager|MockObject */ private $schemaManager; - /** @var TableDefinition */ + /** @var TableDefinition|MockObject */ private $migrationTable; - /** @var AbstractPlatform */ + /** @var AbstractPlatform|MockObject */ private $platform; - /** @var TableUpdater */ + /** @var TableUpdater|MockObject */ private $migrationTableUpdater; public function testUpdateMigrationTable() : void diff --git a/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php b/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php index db089143b7..d2c105a135 100644 --- a/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/AliasResolverTest.php @@ -6,11 +6,12 @@ use Doctrine\Migrations\MigrationRepository; use Doctrine\Migrations\Version\AliasResolver; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; final class AliasResolverTest extends TestCase { - /** @var MigrationRepository */ + /** @var MigrationRepository|MockObject */ private $migrationRepository; /** @var AliasResolver */ @@ -35,7 +36,7 @@ public function testResolveVersionAlias( ->method($expectedMethod) ->willReturn($expectedVersion); - if ($expectedArgument) { + if ($expectedArgument !== null) { $expectation->with($expectedArgument); } } diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php index 4c6ce724f5..4ef64dbae2 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php @@ -10,6 +10,9 @@ class ExecutionResultTest extends TestCase { + /** @var ExecutionResult */ + private $versionExecutionResult; + public function testHasSql() : void { self::assertTrue($this->versionExecutionResult->hasSql()); diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php index 77618289f1..ade44a96fb 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -19,27 +19,28 @@ use Doctrine\Migrations\Version\ExecutionResult; use Doctrine\Migrations\Version\Executor; use Doctrine\Migrations\Version\Version; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Stopwatch\StopwatchEvent; class ExecutorTest extends TestCase { - /** @var Configuration */ + /** @var Configuration|MockObject */ private $configuration; - /** @var Connection */ + /** @var Connection|MockObject */ private $connection; - /** @var SchemaDiffProviderInterface */ + /** @var SchemaDiffProviderInterface|MockObject */ private $schemaDiffProvider; - /** @var OutputWriter */ + /** @var OutputWriter|MockObject */ private $outputWriter; - /** @var ParameterFormatter */ + /** @var ParameterFormatter|MockObject */ private $parameterFormatter; - /** @var Stopwatch */ + /** @var Stopwatch|MockObject */ private $stopwatch; /** @var Executor */ @@ -48,7 +49,7 @@ class ExecutorTest extends TestCase /** @var Version */ private $version; - /** @var AbstractMigration */ + /** @var VersionExecutorTestMigration */ private $migration; public function testAddSql() : void diff --git a/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php b/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php index 65ccf6537f..3887298914 100644 --- a/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\Configuration\Configuration; -use Doctrine\Migrations\Tests\VersionExecutor; use Doctrine\Migrations\Version\ExecutorInterface; use Doctrine\Migrations\Version\Factory; use Doctrine\Migrations\Version\Version; @@ -18,7 +17,7 @@ final class FactoryTest extends TestCase /** @var Configuration */ private $configuration; - /** @var VersionExecutor */ + /** @var ExecutorInterface */ private $versionExecutor; /** @var Factory */ diff --git a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php index 3aa2c8a236..1f66d0a195 100644 --- a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php @@ -83,8 +83,12 @@ public function testShowSqlStatementsParameters() : void $configuration = $this->getSqliteConfiguration(); $configuration->setOutputWriter($outputWriter); - $version = $this->createTestVersion($configuration, '0004', VersionOutputSqlWithParam::class); - $version->getMigration()->setParam([ + $version = $this->createTestVersion($configuration, '0004', VersionOutputSqlWithParam::class); + $migration = $version->getMigration(); + + self::assertInstanceOf(VersionOutputSqlWithParam::class, $migration); + + $migration->setParam([ 0 => 456, 1 => 'tralala', 2 => 456, @@ -102,8 +106,12 @@ public function testShowSqlStatementsParametersWithTypes() : void $configuration = $this->getSqliteConfiguration(); $configuration->setOutputWriter($outputWriter); - $version = $this->createTestVersion($configuration, '0004', VersionOutputSqlWithParamAndType::class); - $version->getMigration()->setParam([ + $version = $this->createTestVersion($configuration, '0004', VersionOutputSqlWithParamAndType::class); + $migration = $version->getMigration(); + + self::assertInstanceOf(VersionOutputSqlWithParamAndType::class, $migration); + + $migration->setParam([ 0 => [ 456, 3, @@ -111,7 +119,7 @@ public function testShowSqlStatementsParametersWithTypes() : void ], ]); - $version->getMigration()->setType([Connection::PARAM_INT_ARRAY]); + $migration->setType([Connection::PARAM_INT_ARRAY]); $version->execute(Direction::UP, (new MigratorConfiguration()) ->setDryRun(true)); @@ -178,10 +186,12 @@ public function testAddSql() : void VersionDummy::class ); - self::assertNull($version->addSql('SELECT * FROM foo')); - self::assertNull($version->addSql('SELECT * FROM foo')); - self::assertNull($version->addSql('SELECT * FROM foo WHERE id = ?', [1])); - self::assertNull($version->addSql('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT])); + $version->addSql('SELECT * FROM foo'); + $version->addSql('SELECT * FROM foo'); + $version->addSql('SELECT * FROM foo WHERE id = ?', [1]); + $version->addSql('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT]); + + self::markTestIncomplete('Does not perform any real assertion.'); } /** @@ -523,7 +533,7 @@ public static function dryRunTypes() : array 'doctrine_param' => [[[1, 2, 3, 4, 5]], [Connection::PARAM_INT_ARRAY], '[1, 2, 3, 4, 5]'], 'doctrine_param_grouped' => [[[1, 2], [3, 4, 5]], [Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY], '[1, 2], [3, 4, 5]'], 'boolean' => [[true], [''], '[true]'], - 'object' => [[new stdClass('test')], [''], '[?]'], + 'object' => [[new stdClass()], [''], '[?]'], ]; } @@ -547,13 +557,16 @@ public function testDryRunWithParametersOfComplexTypesCorrectFormatsParameters( $config = $this->getSqliteConfiguration(); $config->setOutputWriter($ow); - $version = $this->createTestVersion( + $version = $this->createTestVersion( $config, '006', VersionDryRunTypes::class ); + $migration = $version->getMigration(); + + self::assertInstanceOf(VersionDryRunTypes::class, $migration); - $version->getMigration()->setParam($value, $type); + $migration->setParam($value, $type); $version->execute(Direction::UP, (new MigratorConfiguration()) ->setDryRun(true)); @@ -580,7 +593,11 @@ public function testRunWithInsertNullValue() : void VersionDryRunTypes::class ); - $version->getMigration()->setParam([null], []); + $migration = $version->getMigration(); + + self::assertInstanceOf(VersionDryRunTypes::class, $migration); + + $migration->setParam([null], []); $version->execute(Direction::UP, (new MigratorConfiguration()) ->setDryRun(true)); @@ -612,7 +629,7 @@ public function testExecutedAtTimeZone(string $timeZone) : void $now = (new DateTimeImmutable('now'))->setTimezone(new DateTimeZone('UTC')); self::assertSame($now->format('Y-m-d H:i'), date('Y-m-d H:i', strtotime($versionData['executed_at']))); - self::assertSame($timeZone, $version->getExecutedAt()->getTimeZone()->getName()); + self::assertSame($timeZone, $version->getExecutedAt()->getTimezone()->getName()); } /** From e2a762312751f03602b249aac74325074dd8fd2d Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Thu, 13 Sep 2018 16:09:29 +0100 Subject: [PATCH 3/4] Fix tests that don't make any assertions. --- lib/Doctrine/Migrations/OutputWriter.php | 12 +++++++++++- lib/Doctrine/Migrations/Version/Executor.php | 2 +- .../Migrations/Tests/OutputWriterTest.php | 2 +- .../Migrations/Tests/Version/VersionTest.php | 17 +++++++---------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/Migrations/OutputWriter.php b/lib/Doctrine/Migrations/OutputWriter.php index f0d9b29678..575ce8ebc0 100644 --- a/lib/Doctrine/Migrations/OutputWriter.php +++ b/lib/Doctrine/Migrations/OutputWriter.php @@ -12,10 +12,15 @@ class OutputWriter /** @var callable */ private $callback; + /** @var string */ + private $lastMessage = ''; + public function __construct(?callable $callback = null) { if ($callback === null) { - $callback = static function ($message) : void { + + $callback = static function (string $message) : void { + $this->lastMessage = $message; }; } @@ -31,4 +36,9 @@ public function write(string $message) : void { ($this->callback)($message); } + + public function getLastMessage() : string + { + return $this->lastMessage; + } } diff --git a/lib/Doctrine/Migrations/Version/Executor.php b/lib/Doctrine/Migrations/Version/Executor.php index aafad0bd13..280bcbe926 100644 --- a/lib/Doctrine/Migrations/Version/Executor.php +++ b/lib/Doctrine/Migrations/Version/Executor.php @@ -26,7 +26,7 @@ * * @internal */ -final class Executor implements ExecutorInterface +class Executor implements ExecutorInterface { /** @var Configuration */ private $configuration; diff --git a/tests/Doctrine/Migrations/Tests/OutputWriterTest.php b/tests/Doctrine/Migrations/Tests/OutputWriterTest.php index 1b53ceb7e5..253e7e8843 100644 --- a/tests/Doctrine/Migrations/Tests/OutputWriterTest.php +++ b/tests/Doctrine/Migrations/Tests/OutputWriterTest.php @@ -21,7 +21,7 @@ public function testDefaultCallback() : void $outputWriter->write('test message'); - self::markTestIncomplete('Does not perform any real assertion.'); + self::assertSame('test message', $outputWriter->getLastMessage()); } public function testWrite() : void diff --git a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php index 1f66d0a195..d39df91d48 100644 --- a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php @@ -180,18 +180,15 @@ public function testAddSql() : void { $configuration = $this->getSqliteConfiguration(); - $version = $this->createTestVersion( - $configuration, - '003', - VersionDummy::class - ); + $versionExecutor = $this->createMock(Executor::class); - $version->addSql('SELECT * FROM foo'); - $version->addSql('SELECT * FROM foo'); - $version->addSql('SELECT * FROM foo WHERE id = ?', [1]); - $version->addSql('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT]); + $versionExecutor->expects(self::once()) + ->method('addSql') + ->with('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT]); - self::markTestIncomplete('Does not perform any real assertion.'); + $version = new Version($configuration, '003', VersionDummy::class, $versionExecutor); + + $version->addSql('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT]); } /** From 3d7a262db1cf7d50669acef07a5bce6d69078824 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Thu, 13 Sep 2018 17:18:53 +0100 Subject: [PATCH 4/4] Fix PHPStan Level 7 errors in tests. --- .../Migrations/MigrationRepository.php | 12 +++++---- lib/Doctrine/Migrations/OutputWriter.php | 3 +-- .../Migrations/Tools/BytesFormatter.php | 2 +- .../Helper/MigrationDirectoryHelper.php | 5 ---- phpstan.neon.dist | 1 + .../Migrations/Tests/BoxPharCompileTest.php | 5 ++++ .../AbstractConfigurationTest.php | 15 ++++++++--- .../AbstractFileConfigurationTest.php | 3 +++ .../Tests/Configuration/ConfigurationTest.php | 22 ++++++++++++--- .../Migrations/Tests/ConfigurationTest.php | 8 +++--- .../Migrations/Tests/FileQueryWriterTest.php | 2 +- .../Tests/Finder/RecursiveRegexFinderTest.php | 2 +- .../Migrations/Tests/Functional/CliTest.php | 11 +++++++- .../Tests/Functional/FunctionalTest.php | 10 ++++--- tests/Doctrine/Migrations/Tests/Helper.php | 23 +++++++++++++--- .../Migrations/Tests/MigrationTestCase.php | 10 +++++-- .../Migrations/Tests/MigratorTest.php | 6 ++--- .../Tests/Provider/OrmSchemaProviderTest.php | 2 -- .../Migrations/Tests/StopwatchTest.php | 4 --- .../Tests/Stub/AbstractMigrationStub.php | 2 +- .../Tests/Stub/EventVerificationListener.php | 2 +- .../Tests/Stub/VersionDryRunTypes.php | 6 ++--- .../Tests/Stub/VersionOutputSqlWithParam.php | 4 +-- .../Stub/VersionOutputSqlWithParamAndType.php | 4 +-- .../Console/Command/AbstractCommandTest.php | 18 ++++++------- .../Console/Command/MigrationStatusTest.php | 3 +-- .../Console/Command/UpToDateCommandTest.php | 2 +- .../Tests/Tools/Console/ConsoleRunnerTest.php | 8 +++--- .../Helper/ConfigurationHelperTest.php | 27 +++---------------- .../Helper/MigrationDirectoryHelperTest.php | 7 ----- .../Tests/Tracking/TableDefinitionTest.php | 4 +-- .../Tests/Version/ExecutionResultTest.php | 5 +++- .../Migrations/Tests/Version/ExecutorTest.php | 3 --- .../Migrations/Tests/Version/FactoryTest.php | 2 -- .../Migrations/Tests/Version/VersionTest.php | 14 ++++++---- 35 files changed, 142 insertions(+), 115 deletions(-) diff --git a/lib/Doctrine/Migrations/MigrationRepository.php b/lib/Doctrine/Migrations/MigrationRepository.php index 737ae4a537..85ddc3b9d5 100644 --- a/lib/Doctrine/Migrations/MigrationRepository.php +++ b/lib/Doctrine/Migrations/MigrationRepository.php @@ -19,14 +19,12 @@ use function array_map; use function array_search; use function array_unshift; -use function assert; use function class_exists; use function count; use function end; use function get_class; use function implode; use function is_array; -use function is_int; use function ksort; use function sprintf; use function substr; @@ -345,14 +343,18 @@ public function getRelativeVersion(string $version, int $delta) : ?string $offset = array_search($version, $versions, true); - assert($offset === false || is_int($offset)); + if ($offset === false) { + return null; + } + + $relativeVersion = ((int) $offset) + $delta; - if ($offset === false || ! isset($versions[$offset + $delta])) { + if (! isset($versions[$relativeVersion])) { // Unknown version or delta out of bounds. return null; } - return $versions[$offset + $delta]; + return $versions[$relativeVersion]; } public function getDeltaVersion(string $delta) : ?string diff --git a/lib/Doctrine/Migrations/OutputWriter.php b/lib/Doctrine/Migrations/OutputWriter.php index 575ce8ebc0..ebb04adfb0 100644 --- a/lib/Doctrine/Migrations/OutputWriter.php +++ b/lib/Doctrine/Migrations/OutputWriter.php @@ -18,8 +18,7 @@ class OutputWriter public function __construct(?callable $callback = null) { if ($callback === null) { - - $callback = static function (string $message) : void { + $callback = function (string $message) : void { $this->lastMessage = $message; }; } diff --git a/lib/Doctrine/Migrations/Tools/BytesFormatter.php b/lib/Doctrine/Migrations/Tools/BytesFormatter.php index 2c6c3e9a30..91caabd057 100644 --- a/lib/Doctrine/Migrations/Tools/BytesFormatter.php +++ b/lib/Doctrine/Migrations/Tools/BytesFormatter.php @@ -22,6 +22,6 @@ public static function formatBytes(int $size, int $precision = 2) : string $base = log($size, 1024); $suffixes = ['', 'K', 'M', 'G', 'T']; - return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; + return round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int) floor($base)]; } } diff --git a/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php b/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php index 00825fd143..d3a01ccf5c 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php +++ b/lib/Doctrine/Migrations/Tools/Console/Helper/MigrationDirectoryHelper.php @@ -71,9 +71,4 @@ private function createDirIfNotExists(string $dir) : void mkdir($dir, 0755, true); } - - public function getName() : string - { - return 'MigrationDirectory'; - } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index febed60215..1722859116 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,6 +10,7 @@ parameters: - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Functional/_files autoload_files: - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/realpath.php ignoreErrors: # Ignore proxy manager magic - '~ProxyManager\\Proxy\\VirtualProxyInterface~' diff --git a/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php b/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php index cfb29ed1e5..d630dacd3d 100644 --- a/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php +++ b/tests/Doctrine/Migrations/Tests/BoxPharCompileTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; +use function assert; use function file_exists; use function realpath; use function sprintf; @@ -25,6 +26,8 @@ public function testCompile() : void $boxPharPath = realpath($boxPharPath); + assert($boxPharPath !== false); + $compilePharCommand = sprintf('php %s compile -vvv', $boxPharPath); $process = new Process($compilePharCommand); @@ -32,6 +35,8 @@ public function testCompile() : void $doctrinePharPath = realpath(__DIR__ . '/../../../../build/doctrine-migrations.phar'); + assert($doctrinePharPath !== false); + self::assertTrue($process->isSuccessful()); self::assertTrue(file_exists($doctrinePharPath)); diff --git a/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php index 4ef51ce0ba..99811eb21e 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/AbstractConfigurationTest.php @@ -156,8 +156,13 @@ public function testConfigurationFileNotExists() : void public function testLoadMigrationsList() : void { - self::assertInstanceOf(AbstractFileConfiguration::class, $this->loadConfiguration('migrations_list')); - self::assertInstanceOf(AbstractFileConfiguration::class, $this->loadConfiguration('migrations_list2')); + $configuration1 = $this->loadConfiguration('migrations_list'); + + self::assertContains('migrations_list', $configuration1->getFile()); + + $configuration2 = $this->loadConfiguration('migrations_list2'); + + self::assertContains('migrations_list2', $configuration2->getFile()); } /** @@ -165,10 +170,12 @@ public function testLoadMigrationsList() : void */ public function testThatTheOrderOfConfigKeysDoesNotMatter(string $file) : void { - self::assertInstanceOf(AbstractFileConfiguration::class, $this->loadConfiguration($file)); + $configuration = $this->loadConfiguration($file); + + self::assertContains($file, $configuration->getFile()); } - /** @return string[] */ + /** @return string[][] */ public function getConfigWithKeysInVariousOrder() : array { return [ diff --git a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php index a31fd74b2d..c74e08c947 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/AbstractFileConfigurationTest.php @@ -8,6 +8,7 @@ use Doctrine\Migrations\Configuration\AbstractFileConfiguration; use Doctrine\Migrations\Configuration\Exception\InvalidConfigurationKey; use PHPUnit\Framework\TestCase; +use function assert; use function basename; use function chdir; use function getcwd; @@ -24,6 +25,8 @@ public function testLoadChecksCurrentWorkingDirectory() : void { $cwd = getcwd(); + assert($cwd !== false); + chdir(__DIR__); $file = basename(__FILE__); diff --git a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php index 05ba5c9385..8e38b67bd0 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php @@ -45,9 +45,17 @@ public function testConstructorSetsOutputWriter() : void public function testOutputWriterIsCreatedIfNotInjected() : void { - $configuration = new Configuration($this->getConnectionMock()); + $dependencyFactory = $this->createMock(DependencyFactory::class); + + $outputWriter = $this->getOutputWriterMock(); + + $dependencyFactory->expects(self::once()) + ->method('getOutputWriter') + ->willReturn($outputWriter); - self::assertInstanceOf(OutputWriter::class, $configuration->getOutputWriter()); + $configuration = new Configuration($this->getConnectionMock(), null, null, null, $dependencyFactory); + + self::assertSame($outputWriter, $configuration->getOutputWriter()); } public function testOutputWriterCanBeSet() : void @@ -85,7 +93,10 @@ public function testVersionsTryToGetLoadedIfNotAlreadyLoadedWhenAccessingMethodT $configuration->setMigrationsNamespace(str_replace('\Version1Test', '', Version1Test::class)); $configuration->setMigrationsDirectory(__DIR__ . '/../Stub/Configuration/AutoloadVersions'); - $result = call_user_func_array([$configuration, $method], $args); + /** @var callable $callable */ + $callable = [$configuration, $method]; + + $result = call_user_func_array($callable, $args); if ($method === 'getMigrationsToExecute') { $result = array_keys($result); @@ -122,7 +133,10 @@ public function testVersionsTryToGetLoadedIfNotAlreadyLoadedWhenAccessingMethodT ); $migrator->migrate('3Test'); - $result = call_user_func_array([$configuration, $method], $args); + /** @var callable $callable */ + $callable = [$configuration, $method]; + + $result = call_user_func_array($callable, $args); if ($method === 'getMigrationsToExecute') { $result = array_keys($result); diff --git a/tests/Doctrine/Migrations/Tests/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/ConfigurationTest.php index ec173e46ea..2bf43ace6b 100644 --- a/tests/Doctrine/Migrations/Tests/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/ConfigurationTest.php @@ -12,7 +12,6 @@ use Doctrine\Migrations\Tests\Stub\Version1Test; use Doctrine\Migrations\Tests\Stub\Version2Test; use Doctrine\Migrations\Tests\Stub\Version3Test; -use Doctrine\Migrations\Version\Version; use function sys_get_temp_dir; class ConfigurationTest extends MigrationTestCase @@ -131,7 +130,6 @@ public function testRegisterMigration() : void self::assertTrue($config->hasVersion('1234')); $version = $config->getVersion('1234'); - self::assertInstanceOf(Version::class, $version); self::assertSame('1234', $version->getVersion()); self::assertFalse($version->isMigrated()); } @@ -147,10 +145,10 @@ public function testRegisterMigrations() : void self::assertCount(2, $config->getMigrations(), 'Two Migration registered.'); $version = $config->getVersion('1234'); - self::assertInstanceOf(Version::class, $version); + self::assertSame('1234', $version->getVersion()); $version = $config->getVersion('1235'); - self::assertInstanceOf(Version::class, $version); + self::assertSame('1235', $version->getVersion()); } public function testRegisterDuplicateVersion() : void @@ -348,7 +346,7 @@ public function testGetVersionAutoloadVersion(string $version) : void $result = $config->getVersion($version); - self::assertNotNull($result); + self::assertSame($version, $result->getVersion()); } public function testGetVersionNotFound() : void diff --git a/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php b/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php index 782004e122..2d484828f9 100644 --- a/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php +++ b/tests/Doctrine/Migrations/Tests/FileQueryWriterTest.php @@ -85,7 +85,7 @@ public function testWrite( } } - /** @return string[][] */ + /** @return mixed[][] */ public function writeProvider() : array { $outputWriter = $this->createMock(OutputWriter::class); diff --git a/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php b/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php index eabe38b91c..2d60622f2c 100644 --- a/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php +++ b/tests/Doctrine/Migrations/Tests/Finder/RecursiveRegexFinderTest.php @@ -56,7 +56,7 @@ public function testFindMigrationsReturnsTheExpectedFilesFromDirectory() : void self::assertArrayHasKey($version, $migrations); self::assertSame($namespace, $migrations[$version]); } - $migrationsForTestSort = (array) $migrations; + $migrationsForTestSort = $migrations; asort($migrationsForTestSort); diff --git a/tests/Doctrine/Migrations/Tests/Functional/CliTest.php b/tests/Doctrine/Migrations/Tests/Functional/CliTest.php index e75905cc61..856f3f1037 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/CliTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/CliTest.php @@ -24,6 +24,7 @@ use Symfony\Component\Console\Input\ArrayInput; use const DIRECTORY_SEPARATOR; use function array_merge; +use function assert; use function count; use function file_exists; use function file_get_contents; @@ -326,7 +327,15 @@ private function getFileContentsForLatestVersion() : string $versionClassName = reset($versions); $versionClassReflected = new ReflectionClass($versionClassName); - return file_get_contents($versionClassReflected->getFileName()); + $fileName = $versionClassReflected->getFileName(); + + assert($fileName !== false); + + $contents = file_get_contents($fileName); + + assert($contents !== false); + + return $contents; } } diff --git a/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php b/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php index 8f9478cab9..fa80ba8667 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php @@ -31,9 +31,11 @@ use Doctrine\Migrations\Version\Version; use Symfony\Component\Process\Process; use Symfony\Component\Stopwatch\Stopwatch as SymfonyStopwatch; +use function assert; use function file_exists; use function get_class_methods; use function in_array; +use function is_array; use function sprintf; use function strtotime; use function unlink; @@ -363,7 +365,7 @@ public function testSchemaChangeAreNotTakenIntoAccountInPreAndPostMethod() : voi $version = $this->createTestVersion($this->config, '1', MigrationModifySchemaInPreAndPost::class); self::assertFalse($this->config->hasVersionMigrated($version)); - $queries = $version->execute('up'); + $queries = $version->execute('up')->getSql(); $schema = $this->connection->getSchemaManager()->createSchema(); self::assertTrue($schema->hasTable('foo'), 'The table foo is not present'); @@ -375,7 +377,7 @@ public function testSchemaChangeAreNotTakenIntoAccountInPreAndPostMethod() : voi self::assertNotContains('bar2', $query); } - $queries = $version->execute('down'); + $queries = $version->execute('down')->getSql(); $schema = $this->connection->getSchemaManager()->createSchema(); self::assertFalse($schema->hasTable('foo'), 'The table foo is present'); @@ -389,7 +391,7 @@ public function testSchemaChangeAreNotTakenIntoAccountInPreAndPostMethod() : voi } /** - * @return string[][] + * @return mixed[][] */ public function provideTestMigrationNames() : array { @@ -517,6 +519,8 @@ public function testMigrationExecutedAt() : void $row = $this->config->getConnection() ->fetchAssoc('SELECT * FROM test_migrations_table'); + assert(is_array($row)); + self::assertSame('1', $row['current_version']); self::assertTrue(isset($row['executed_at'])); self::assertNotNull($row['executed_at']); diff --git a/tests/Doctrine/Migrations/Tests/Helper.php b/tests/Doctrine/Migrations/Tests/Helper.php index 917a9a101e..fde13c7678 100644 --- a/tests/Doctrine/Migrations/Tests/Helper.php +++ b/tests/Doctrine/Migrations/Tests/Helper.php @@ -22,10 +22,25 @@ public static function deleteDir(string $path) : bool if ($path === '') { return false; } - $class_func = [self::class, __FUNCTION__]; - return is_file($path) ? - @unlink($path) : - array_map($class_func, glob($path . '/*')) === @rmdir($path); + $classFunction = [self::class, __FUNCTION__]; + + if (is_file($path)) { + @unlink($path); + + return true; + } + + $files = glob($path . '/*'); + + if ($files !== []) { + array_map($classFunction, $files); + + @rmdir($path); + + return true; + } + + return false; } } diff --git a/tests/Doctrine/Migrations/Tests/MigrationTestCase.php b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php index 7386d3b9b1..5b442233d2 100644 --- a/tests/Doctrine/Migrations/Tests/MigrationTestCase.php +++ b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php @@ -12,14 +12,15 @@ use Doctrine\Migrations\Stopwatch; use Exception; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Stopwatch\Stopwatch as SymfonyStopwatch; +use function assert; use function fopen; use function fwrite; use function glob; use function is_dir; use function is_file; +use function is_resource; use function mkdir; use function realpath; use function rewind; @@ -30,7 +31,7 @@ abstract class MigrationTestCase extends TestCase /** @var OutputWriter */ private $outputWriter; - /** @var Output */ + /** @var StreamOutput */ protected $output; public function getSqliteConnection() : Connection @@ -53,6 +54,8 @@ public function getOutputStream() : StreamOutput { $stream = fopen('php://memory', 'r+', false); + assert(is_resource($stream)); + return new StreamOutput($stream); } @@ -68,6 +71,9 @@ public function getOutputStreamContent(StreamOutput $streamOutput) : string public function getInputStream(string $input) { $stream = fopen('php://memory', 'r+', false); + + assert(is_resource($stream)); + fwrite($stream, $input); rewind($stream); diff --git a/tests/Doctrine/Migrations/Tests/MigratorTest.php b/tests/Doctrine/Migrations/Tests/MigratorTest.php index 264c5459af..838896e20b 100644 --- a/tests/Doctrine/Migrations/Tests/MigratorTest.php +++ b/tests/Doctrine/Migrations/Tests/MigratorTest.php @@ -140,7 +140,7 @@ public function testGetSql(?string $to) : void ->setMethods(['migrate']) ->getMock(); - $expected = ['something']; + $expected = [['something']]; $migration->expects(self::once()) ->method('migrate') @@ -152,7 +152,7 @@ public function testGetSql(?string $to) : void self::assertSame($expected, $result); } - /** @return string[]|null[] */ + /** @return mixed[][] */ public function getSqlProvider() : array { return [ @@ -225,7 +225,7 @@ public function testWriteSqlFile(string $path, string $from, ?string $to, array } /** - * @return string[][] + * @return mixed[][] */ public function writeSqlFileProvider() : array { diff --git a/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php b/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php index bb2bf6bd7d..b437edfd16 100644 --- a/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php +++ b/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php @@ -5,7 +5,6 @@ namespace Doctrine\Migrations\Tests\Provider; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\Provider\OrmSchemaProvider; use Doctrine\Migrations\Tests\MigrationTestCase; use Doctrine\ORM\Configuration; @@ -35,7 +34,6 @@ class OrmSchemaProviderTest extends MigrationTestCase public function testCreateSchemaFetchesMetadataFromEntityManager() : void { $schema = $this->ormProvider->createSchema(); - self::assertInstanceOf(Schema::class, $schema); self::assertTrue($schema->hasTable('sample_entity')); $table = $schema->getTable('sample_entity'); self::assertTrue($table->hasColumn('id')); diff --git a/tests/Doctrine/Migrations/Tests/StopwatchTest.php b/tests/Doctrine/Migrations/Tests/StopwatchTest.php index a79e50949b..022a29236b 100644 --- a/tests/Doctrine/Migrations/Tests/StopwatchTest.php +++ b/tests/Doctrine/Migrations/Tests/StopwatchTest.php @@ -7,7 +7,6 @@ use Doctrine\Migrations\Stopwatch; use PHPUnit\Framework\TestCase; use Symfony\Component\Stopwatch\Stopwatch as SymfonyStopwatch; -use Symfony\Component\Stopwatch\StopwatchEvent; class StopwatchTest extends TestCase { @@ -18,12 +17,9 @@ public function testStart() : void { $stopwatchEvent = $this->stopwatch->start('test'); - self::assertInstanceOf(StopwatchEvent::class, $stopwatchEvent); self::assertSame('default', $stopwatchEvent->getCategory()); $stopwatchEvent->stop(); - - self::assertNotNull($stopwatchEvent->getDuration()); } protected function setUp() : void diff --git a/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php b/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php index ef9e9dcf21..6061903cf1 100644 --- a/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php +++ b/tests/Doctrine/Migrations/Tests/Stub/AbstractMigrationStub.php @@ -18,7 +18,7 @@ public function down(Schema $schema) : void { } - public function exposedWrite(?string $message = null) : void + public function exposedWrite(string $message) : void { $this->write($message); } diff --git a/tests/Doctrine/Migrations/Tests/Stub/EventVerificationListener.php b/tests/Doctrine/Migrations/Tests/Stub/EventVerificationListener.php index c363878d2a..c390e7b69c 100644 --- a/tests/Doctrine/Migrations/Tests/Stub/EventVerificationListener.php +++ b/tests/Doctrine/Migrations/Tests/Stub/EventVerificationListener.php @@ -10,7 +10,7 @@ final class EventVerificationListener implements EventSubscriber { - /** @var EventArgs[] */ + /** @var EventArgs[][] */ public $events = []; /** @return string[] */ diff --git a/tests/Doctrine/Migrations/Tests/Stub/VersionDryRunTypes.php b/tests/Doctrine/Migrations/Tests/Stub/VersionDryRunTypes.php index 66b86cff60..3e7307a668 100644 --- a/tests/Doctrine/Migrations/Tests/Stub/VersionDryRunTypes.php +++ b/tests/Doctrine/Migrations/Tests/Stub/VersionDryRunTypes.php @@ -9,15 +9,15 @@ class VersionDryRunTypes extends AbstractMigration { - /** @var int[] */ + /** @var mixed[] */ private $value; /** @var int[] */ private $type; /** - * @param int[] $value - * @param int[] $type + * @param mixed[] $value + * @param int[] $type */ public function setParam(array $value, array $type) : void { diff --git a/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParam.php b/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParam.php index 7dff0469ab..1852f679ef 100644 --- a/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParam.php +++ b/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParam.php @@ -9,14 +9,14 @@ class VersionOutputSqlWithParam extends AbstractMigration { - /** @var int[] */ + /** @var mixed[] */ private $param = [ 'param1' => 1, 'param2' => 2, 'param3' => 3, ]; - /** @param int[] $param */ + /** @param mixed[] $param */ public function setParam(array $param) : void { $this->param = $param; diff --git a/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParamAndType.php b/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParamAndType.php index a1fa918e7c..e758272276 100644 --- a/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParamAndType.php +++ b/tests/Doctrine/Migrations/Tests/Stub/VersionOutputSqlWithParamAndType.php @@ -10,13 +10,13 @@ class VersionOutputSqlWithParamAndType extends AbstractMigration { - /** @var int[] */ + /** @var mixed[] */ private $param = ['param1' => 1]; /** @var int[] */ private $type = [Connection::PARAM_STR_ARRAY]; - /** @param int[] $param */ + /** @param mixed[] $param */ public function setParam(array $param) : void { $this->param = $param; diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php index f14cc2f5dc..054c9e94f7 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/AbstractCommandTest.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Output\OutputInterface; +use function assert; use function chdir; use function getcwd; @@ -46,7 +47,7 @@ public function invokeMigrationConfigurationGetter( ['command'] ); - if ($helperSet !== null && $helperSet instanceof HelperSet) { + if ($helperSet instanceof HelperSet) { $command->setHelperSet($helperSet); } else { $command->setHelperSet(new HelperSet()); @@ -127,7 +128,6 @@ public function testMigrationConfigurationReturnsConnectionFromHelperSet() : voi $actualConfiguration = $this->invokeMigrationConfigurationGetter($input); - self::assertInstanceOf(Configuration::class, $actualConfiguration); self::assertSame('pdo_sqlite', $actualConfiguration->getConnection()->getDriver()->getName()); } @@ -148,7 +148,6 @@ public function testMigrationConfigurationReturnsConnectionFromInputOption() : v $actualConfiguration = $this->invokeMigrationConfigurationGetter($input); - self::assertInstanceOf(Configuration::class, $actualConfiguration); self::assertSame('pdo_sqlite', $actualConfiguration->getConnection()->getDriver()->getName()); } @@ -188,7 +187,6 @@ public function testMigrationConfigurationReturnsConnectionFromConfigurationIfNo $configuration = new Configuration($connection); $actualConfiguration = $this->invokeMigrationConfigurationGetter($input, $configuration, true); - self::assertInstanceOf(Configuration::class, $actualConfiguration); self::assertSame($connection, $actualConfiguration->getConnection()); self::assertSame('doctrine_migration_versions', $actualConfiguration->getMigrationsTableName()); self::assertNull($actualConfiguration->getMigrationsNamespace()); @@ -300,11 +298,7 @@ private function invokeAbstractCommandConfirmation( $input->setStream($this->getInputStream($response . "\n")); - if ($helper instanceof QuestionHelper) { - $helperSet = new HelperSet(['question' => $helper]); - } else { - $helperSet = new HelperSet(['dialog' => $helper]); - } + $helperSet = new HelperSet(['question' => $helper]); $command->setHelperSet($helperSet); @@ -326,7 +320,11 @@ public function testAskConfirmation() : void protected function setUp() : void { - $this->originalCwd = getcwd(); + $cwd = getcwd(); + + assert($cwd !== false); + + $this->originalCwd = $cwd; } protected function tearDown() : void diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php index 68b9965e9e..f284f04058 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrationStatusTest.php @@ -16,9 +16,8 @@ class MigrationStatusTest extends MigrationTestCase /** @var string */ private $migrationDirectory; - public function __construct() + protected function setUp() : void { - parent::__construct(null, [], null); $this->migrationDirectory = __DIR__ . '/../../../Stub/migration-empty-folder'; } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php index 27281459d1..6153f6be69 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/UpToDateCommandTest.php @@ -55,7 +55,7 @@ public function testIsUpToDate(array $migrations, array $migratedVersions, int $ } /** - * @return string[][] + * @return mixed[][] */ public function dataIsUpToDate() : array { diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php index abf6887278..fc28aa4435 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php @@ -108,9 +108,11 @@ public function testNotHasDiffCommand() : void public function testCreateApplication() : void { - $actual = ConsoleRunner::createApplication(new HelperSet()); + $helperSet = new HelperSet(); - self::assertInstanceOf(Application::class, $actual); + $application = ConsoleRunner::createApplication($helperSet); + + self::assertSame($helperSet, $application->getHelperSet()); } protected function setUp() : void @@ -126,7 +128,7 @@ protected function setUp() : void class ConsoleRunnerStub extends ConsoleRunner { - /** @var Application|null */ + /** @var Application */ public static $application; /** diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php index a77fc28256..c775736414 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php @@ -6,17 +6,14 @@ use Doctrine\DBAL\Connection; use Doctrine\Migrations\Configuration\ArrayConfiguration; -use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Configuration\JsonConfiguration; -use Doctrine\Migrations\OutputWriter; use Doctrine\Migrations\Tests\MigrationTestCase; use Doctrine\Migrations\Tools\Console\Helper\ConfigurationHelper; -use Doctrine\ORM\Configuration as ORMConfiguration; use InvalidArgumentException; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\StreamOutput; use function copy; use function trim; use function unlink; @@ -26,22 +23,14 @@ class ConfigurationHelperTest extends MigrationTestCase /** @var Connection */ private $connection; - /** @var ORMConfiguration */ - private $configuration; - - /** @var OutputWriter */ - protected $outputWriter; - - /** @var OutputInterface */ + /** @var StreamOutput */ protected $output; - /** @var InputInterface|PHPUnit_Framework_MockObject_MockObject */ + /** @var InputInterface|MockObject */ private $input; protected function setUp() : void { - $this->configuration = $this->getSqliteConfiguration(); - $this->connection = $this->getSqliteConnection(); $this->output = $this->getOutputStream(); @@ -52,13 +41,6 @@ protected function setUp() : void ->getMock(); } - public function testConfigurationHelper() : void - { - $configurationHelper = new ConfigurationHelper($this->connection, $this->configuration); - - self::assertInstanceOf(ConfigurationHelper::class, $configurationHelper); - } - /** * Used in other tests to see if xml or yaml or yml config files are loaded. */ @@ -136,7 +118,6 @@ public function testConfigurationHelperWithoutConfigurationFromSetterAndWithoutO $migrationConfig = $configurationHelper->getMigrationConfig($this->input); - self::assertInstanceOf(Configuration::class, $migrationConfig); self::assertStringMatchesFormat('', $this->getOutputStreamContent($this->output)); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php index fdb092ddcd..9599d8730e 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationDirectoryHelperTest.php @@ -12,13 +12,6 @@ class MigrationDirectoryHelperTest extends MigrationTestCase { - public function testMigrationDirectoryHelper() : void - { - $mirationDirectoryHelper = new MigrationDirectoryHelper($this->getSqliteConfiguration()); - - self::assertInstanceOf(MigrationDirectoryHelper::class, $mirationDirectoryHelper); - } - public function testMigrationDirectoryHelperReturnConfiguredDir() : void { $mirationDirectoryHelper = new MigrationDirectoryHelper($this->getSqliteConfiguration()); diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php index 6820a4acb8..b7367076b9 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableDefinitionTest.php @@ -76,7 +76,7 @@ public function testGetDBALTable() : void self::assertCount(2, $table->getColumns()); self::assertTrue($table->hasOption('test_option')); - self::assertSame(true, $table->getOption('test_option')); + self::assertTrue($table->getOption('test_option')); self::assertTrue($table->hasColumn('version_name')); self::assertTrue($table->getColumn('version_name')->getNotnull()); @@ -102,7 +102,7 @@ public function testGetNewDBALTable() : void self::assertCount(2, $table->getColumns()); self::assertTrue($table->hasOption('test_option')); - self::assertSame(true, $table->getOption('test_option')); + self::assertTrue($table->getOption('test_option')); self::assertTrue($table->hasColumn('version_name')); self::assertTrue($table->getColumn('version_name')->getNotnull()); diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php index 4ef64dbae2..49f8f63eb1 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php @@ -81,10 +81,13 @@ public function testError() : void self::assertTrue($this->versionExecutionResult->hasError()); } - public function testException() : void + public function testExceptionNull() : void { self::assertNull($this->versionExecutionResult->getException()); + } + public function testException() : void + { $exception = new InvalidArgumentException(); $this->versionExecutionResult->setException($exception); diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php index ade44a96fb..ff26d3840a 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -16,7 +16,6 @@ use Doctrine\Migrations\Provider\SchemaDiffProviderInterface; use Doctrine\Migrations\Stopwatch; use Doctrine\Migrations\Version\Direction; -use Doctrine\Migrations\Version\ExecutionResult; use Doctrine\Migrations\Version\Executor; use Doctrine\Migrations\Version\Version; use PHPUnit\Framework\MockObject\MockObject; @@ -120,7 +119,6 @@ public function testExecuteUp() : void $migratorConfiguration ); - self::assertInstanceOf(ExecutionResult::class, $versionExecutionResult); self::assertSame(['SELECT 1', 'SELECT 2'], $versionExecutionResult->getSql()); self::assertSame([[1], [2]], $versionExecutionResult->getParams()); self::assertSame([[3], [4]], $versionExecutionResult->getTypes()); @@ -185,7 +183,6 @@ public function testExecuteDown() : void $migratorConfiguration ); - self::assertInstanceOf(ExecutionResult::class, $versionExecutionResult); self::assertSame(['SELECT 3', 'SELECT 4'], $versionExecutionResult->getSql()); self::assertSame([[5], [6]], $versionExecutionResult->getParams()); self::assertSame([[7], [8]], $versionExecutionResult->getTypes()); diff --git a/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php b/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php index 3887298914..766aa3049e 100644 --- a/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php @@ -9,7 +9,6 @@ use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Version\ExecutorInterface; use Doctrine\Migrations\Version\Factory; -use Doctrine\Migrations\Version\Version; use PHPUnit\Framework\TestCase; final class FactoryTest extends TestCase @@ -30,7 +29,6 @@ public function testCreateVersion() : void VersionFactoryTestMigration::class ); - self::assertInstanceOf(Version::class, $version); self::assertSame($this->configuration, $version->getConfiguration()); self::assertInstanceOf(VersionFactoryTestMigration::class, $version->getMigration()); } diff --git a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php index d39df91d48..4500deef20 100644 --- a/tests/Doctrine/Migrations/Tests/Version/VersionTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/VersionTest.php @@ -164,7 +164,7 @@ public function testGetExecutionState(string $state) : void self::assertNotEmpty($version->getExecutionState()); } - /** @return string[][] */ + /** @return mixed[][] */ public function stateProvider() : array { return [ @@ -242,7 +242,7 @@ public function testWriteSqlFile(string $path, string $direction, array $getSqlR self::assertTrue($version->writeSqlFile($path, $direction)); } - /** @return string[][] */ + /** @return mixed[][] */ public function writeSqlFileProvider() : array { return [ @@ -382,7 +382,7 @@ public function testWriteSqlWriteToTheCorrectColumnName( } } - /** @return string[] */ + /** @return string[][] */ public function sqlWriteProvider() : array { return [ @@ -443,7 +443,6 @@ public function testWriteSqlFileShouldUseStandardCommentMarkerInSql() : void /** @var vfsStreamFile $sqlMigrationFile */ $sqlMigrationFile = current($sqlFilesDir->getChildren()); - self::assertInstanceOf(vfsStreamFile::class, $sqlMigrationFile); self::assertNotRegExp('/^\s*#/m', $sqlMigrationFile->getContent()); } @@ -626,7 +625,12 @@ public function testExecutedAtTimeZone(string $timeZone) : void $now = (new DateTimeImmutable('now'))->setTimezone(new DateTimeZone('UTC')); self::assertSame($now->format('Y-m-d H:i'), date('Y-m-d H:i', strtotime($versionData['executed_at']))); - self::assertSame($timeZone, $version->getExecutedAt()->getTimezone()->getName()); + + $executedAt = $version->getExecutedAt(); + + self::assertNotNull($executedAt); + + self::assertSame($timeZone, $executedAt->getTimezone()->getName()); } /**