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 f0d9b29678..ebb04adfb0 100644 --- a/lib/Doctrine/Migrations/OutputWriter.php +++ b/lib/Doctrine/Migrations/OutputWriter.php @@ -12,10 +12,14 @@ 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 = function (string $message) : void { + $this->lastMessage = $message; }; } @@ -31,4 +35,9 @@ public function write(string $message) : void { ($this->callback)($message); } + + public function getLastMessage() : string + { + return $this->lastMessage; + } } 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/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/phpstan.neon.dist b/phpstan.neon.dist index 6a7ab1e9ee..1722859116 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,13 +2,23 @@ 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 + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/realpath.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..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; @@ -20,11 +21,13 @@ 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); + 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 901926f4e7..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; @@ -17,20 +18,22 @@ class AbstractFileConfigurationTest extends TestCase /** @var Connection */ private $connection; - /** @var AbstractFileConfiguration */ + /** @var TestAbstractFileConfiguration */ private $fileConfiguration; public function testLoadChecksCurrentWorkingDirectory() : void { $cwd = getcwd(); + assert($cwd !== false); + chdir(__DIR__); $file = basename(__FILE__); $this->fileConfiguration->load($file); - $this->assertSame(__DIR__ . '/' . $file, $this->fileConfiguration->getFile()); + self::assertSame(__DIR__ . '/' . $file, $this->fileConfiguration->getFile()); chdir($cwd); } @@ -52,50 +55,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..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(); - self::assertInstanceOf(OutputWriter::class, $configuration->getOutputWriter()); + $dependencyFactory->expects(self::once()) + ->method('getOutputWriter') + ->willReturn($outputWriter); + + $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); @@ -167,7 +181,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 +272,7 @@ public function testGetQueryWriterCreatesAnInstanceIfItWasNotConfigured() : void $schemaManager = $this->createMock(AbstractSchemaManager::class); - $conn->expects($this->any()) + $conn->expects(self::any()) ->method('getSchemaManager') ->willReturn($schemaManager); @@ -294,11 +308,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..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(); @@ -25,7 +29,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/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/ConfigurationTest.php index cac57e3523..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 @@ -159,8 +157,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); @@ -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 @@ -455,7 +453,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 7c5791736b..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 */ @@ -28,7 +29,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 +38,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..2d484828f9 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'); @@ -85,14 +85,14 @@ public function testWrite( } } - /** @return string[][] */ + /** @return mixed[][] */ public function writeProvider() : array { $outputWriter = $this->createMock(OutputWriter::class); - $outputWriter->expects($this->atLeastOnce()) + $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/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..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); @@ -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/CliTest.php b/tests/Doctrine/Migrations/Tests/Functional/CliTest.php index faf69700e5..856f3f1037 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; @@ -23,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; @@ -299,7 +301,7 @@ protected function getSchema() : Schema } /** - * @return array|string[] + * @return string[] */ private function findMigrations() : array { @@ -325,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 36518ad4bb..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 { @@ -436,7 +438,7 @@ public function testMigrationWorksWhenNoCallsAreMadeToTheSchema() : void continue; } - $schema->expects($this->never())->method($method); + $schema->expects(self::never())->method($method); } } @@ -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']); @@ -524,7 +528,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 4782849166..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 */ @@ -43,70 +44,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'); @@ -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 071447f0f6..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 */ @@ -39,7 +40,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..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 */ @@ -25,11 +26,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 +56,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 +74,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,13 +93,13 @@ public function testCustomTemplateThrowsInvalidArgumentExceptionWhenTemplateEmpt $customTemplate )); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getCustomTemplate') ->willReturn($customTemplate); $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 57a60f52fd..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 */ @@ -43,11 +44,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/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/MigrationPlanCalculatorTest.php b/tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php index 21dc0388bd..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 */ @@ -21,26 +22,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 +50,7 @@ public function testGetMigrationsToExecuteUp() : void '04' => $version4, ]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getMigratedVersions') ->willReturn([ '02', @@ -72,26 +73,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 +101,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..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 */ @@ -39,12 +40,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 +67,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 +90,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/MigrationTestCase.php b/tests/Doctrine/Migrations/Tests/MigrationTestCase.php index 758219f873..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); @@ -76,7 +82,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 c84c3cd995..838896e20b 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; @@ -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); @@ -134,15 +134,15 @@ 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']) ->getMock(); - $expected = ['something']; + $expected = [['something']]; - $migration->expects($this->once()) + $migration->expects(self::once()) ->method('migrate') ->with($to) ->willReturn($expected); @@ -152,7 +152,7 @@ public function testGetSql(?string $to) : void self::assertSame($expected, $result); } - /** @return string|null[] */ + /** @return mixed[][] */ public function getSqlProvider() : array { return [ @@ -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); @@ -207,16 +207,16 @@ 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']) ->getMock(); - $migration->expects($this->once()) + $migration->expects(self::once()) ->method('getSql') ->with($to) ->willReturn($getSqlReturn); @@ -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/OutputWriterTest.php b/tests/Doctrine/Migrations/Tests/OutputWriterTest.php index c5d12eb1b3..253e7e8843 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::assertSame('test message', $outputWriter->getLastMessage()); } public function testWrite() : void 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/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/RollupTest.php b/tests/Doctrine/Migrations/Tests/RollupTest.php index ac3dd31d55..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 */ @@ -31,7 +32,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 +52,7 @@ public function testRollupTooManyMigrationsException() : void '02' => $version2, ]; - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn($versions); @@ -64,22 +65,22 @@ 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()); + 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 7e44d5221b..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 */ @@ -38,11 +39,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 +56,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/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 e917377eb8..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()); @@ -77,7 +78,7 @@ public function testSetConnection() : void $command->setConnection($connection); - $this->assertSame($connection, $command->getConnection()); + self::assertSame($connection, $command->getConnection()); } public function testGetMigrationConfigurationDefaultsToConnection() : void @@ -89,7 +90,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 +104,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,12 +123,11 @@ 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); - self::assertInstanceOf(Configuration::class, $actualConfiguration); self::assertSame('pdo_sqlite', $actualConfiguration->getConnection()->getDriver()->getName()); } @@ -142,13 +142,12 @@ public function testMigrationConfigurationReturnsConnectionFromInputOption() : v ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['db-configuration', __DIR__ . '/_files/db-config.php'], ])); $actualConfiguration = $this->invokeMigrationConfigurationGetter($input); - self::assertInstanceOf(Configuration::class, $actualConfiguration); self::assertSame('pdo_sqlite', $actualConfiguration->getConnection()->getDriver()->getName()); } @@ -163,7 +162,7 @@ public function testMigrationConfigurationReturnsConfigurationFileOption() : voi ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['configuration', __DIR__ . '/_files/config.yml'], ])); @@ -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()); @@ -217,7 +215,7 @@ public function testMigrationsConfigurationFromCommandLineOverridesInjectedConfi ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['configuration', __DIR__ . '/_files/config.yml'], ])); @@ -247,7 +245,7 @@ public function testInjectedConfigurationIsPreferedOverConfigFileIsCurrentWorkin ->getMock(); $input->method('getOption') - ->will($this->returnValueMap([ + ->will(self::returnValueMap([ ['configuration', null], ])); @@ -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/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/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..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 @@ -27,44 +28,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 +89,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..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 @@ -44,7 +45,7 @@ public function testExecuteThrowsRuntimeException() : void $versions = [$version]; - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getVersions') ->willReturn($versions); @@ -56,36 +57,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 +108,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..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 @@ -28,27 +29,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 +64,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 +99,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 +144,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..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 @@ -31,25 +32,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 +69,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..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 @@ -30,16 +34,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 +56,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 +82,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 +108,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 +134,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 +160,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 +192,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 +237,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 +282,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 +333,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 +404,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 +449,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..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'; } @@ -64,27 +63,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 +120,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..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 */ @@ -33,9 +34,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..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 @@ -29,15 +30,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 +50,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..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 */ @@ -38,11 +39,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 +51,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 +147,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..6153f6be69 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 */ @@ -45,7 +46,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); @@ -54,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/ConnectionLoaderTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConnectionLoaderTest.php index 83ae396ac8..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 */ @@ -30,7 +31,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 +51,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..fc28aa4435 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; /** @@ -30,7 +31,7 @@ public function testRun() : void ConsoleRunnerStub::$application = $application; - $application->expects($this->once()) + $application->expects(self::once()) ->method('run'); ConsoleRunnerStub::run($helperSet, []); @@ -107,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 @@ -125,10 +128,12 @@ protected function setUp() : void class ConsoleRunnerStub extends ConsoleRunner { - /** @var Application|null */ + /** @var Application */ 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/ConfigurationHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/ConfigurationHelperTest.php index 3f45de9dbf..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. */ @@ -72,7 +54,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 +69,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 +82,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 +98,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,13 +112,12 @@ public function testConfigurationHelperWithoutConfigurationFromSetterAndWithoutO { $this->input->method('getOption') ->with('configuration') - ->will($this->returnValue(null)); + ->will(self::returnValue(null)); $configurationHelper = new ConfigurationHelper($this->connection, null); $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/Tools/Console/Helper/MigrationStatusInfosHelperTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php index c880f45c47..ee9d515775 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Helper/MigrationStatusInfosHelperTest.php @@ -9,57 +9,61 @@ 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; 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 +99,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 +115,7 @@ protected function setUp() : void '003', ]); - $this->migrationRepository->expects($this->once()) + $this->migrationRepository->expects(self::once()) ->method('getAvailableVersions') ->willReturn([ '001', @@ -119,11 +123,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..b7367076b9 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 */ @@ -62,11 +63,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]); @@ -75,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()); @@ -88,11 +89,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]); @@ -101,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/Tracking/TableManipulatorTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php index 989c21a456..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 */ @@ -35,18 +36,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 +67,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 +94,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..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 */ @@ -30,11 +31,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 +45,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); @@ -58,75 +59,75 @@ public function testIsCreatedFalse() : void public function testSetUpToDate() : void { - $this->migrationTableStatus->setUpTodate(true); + $this->migrationTableStatus->setUpToDate(true); self::assertTrue($this->migrationTableStatus->isUpToDate()); } 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); - self::assertTrue($this->migrationTableStatus->isUpTodate()); + self::assertTrue($this->migrationTableStatus->isUpToDate()); } 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); - 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 271b4946b1..45467f8a10 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableUpdaterTest.php @@ -14,33 +14,34 @@ 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 { - $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 +50,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 +65,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 +73,7 @@ public function testUpdateMigrationTable() : void ]) ->willReturn($table); - $table->expects($this->any()) + $table->expects(self::any()) ->method('getColumns') ->willReturn([ $versionColumn, @@ -82,27 +83,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 +114,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 +127,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 +142,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 +150,7 @@ public function testUpdateMigrationTableRollback() : void ]) ->willReturn($table); - $table->expects($this->any()) + $table->expects(self::any()) ->method('getColumns') ->willReturn([ $versionColumn, @@ -159,28 +160,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..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 */ @@ -25,17 +26,17 @@ 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); - if ($expectedArgument) { + if ($expectedArgument !== null) { $expectation->with($expectedArgument); } } @@ -61,7 +62,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/ExecutionResultTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutionResultTest.php index 4c6ce724f5..49f8f63eb1 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()); @@ -78,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 8a1a1c3f06..ff26d3840a 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -16,30 +16,30 @@ 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; 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 +48,7 @@ class ExecutorTest extends TestCase /** @var Version */ private $version; - /** @var AbstractMigration */ + /** @var VersionExecutorTestMigration */ private $migration; public function testAddSql() : void @@ -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)"); @@ -119,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()); @@ -135,42 +134,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)"); @@ -184,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()); @@ -214,7 +212,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/FactoryTest.php b/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php index 65ccf6537f..766aa3049e 100644 --- a/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/FactoryTest.php @@ -7,10 +7,8 @@ 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; use PHPUnit\Framework\TestCase; final class FactoryTest extends TestCase @@ -18,7 +16,7 @@ final class FactoryTest extends TestCase /** @var Configuration */ private $configuration; - /** @var VersionExecutor */ + /** @var ExecutorInterface */ private $versionExecutor; /** @var Factory */ @@ -31,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 e4a37850ec..4500deef20 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)); @@ -156,7 +164,7 @@ public function testGetExecutionState(string $state) : void self::assertNotEmpty($version->getExecutionState()); } - /** @return string[][] */ + /** @return mixed[][] */ public function stateProvider() : array { return [ @@ -172,16 +180,15 @@ public function testAddSql() : void { $configuration = $this->getSqliteConfiguration(); - $version = $this->createTestVersion( - $configuration, - '003', - VersionDummy::class - ); + $versionExecutor = $this->createMock(Executor::class); + + $versionExecutor->expects(self::once()) + ->method('addSql') + ->with('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT]); - 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 = new Version($configuration, '003', VersionDummy::class, $versionExecutor); + + $version->addSql('SELECT * FROM foo WHERE id = ?', [1], [PDO::PARAM_INT]); } /** @@ -197,7 +204,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 +230,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); @@ -235,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 [ @@ -375,7 +382,7 @@ public function testWriteSqlWriteToTheCorrectColumnName( } } - /** @return string[] */ + /** @return string[][] */ public function sqlWriteProvider() : array { return [ @@ -436,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()); } @@ -523,7 +529,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 +553,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 +589,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 +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()); } /**