diff --git a/composer.json b/composer.json index fc36ea18..b8469416 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,10 @@ "robmorgan/phinx": "^0.16.0" }, "require-dev": { - "cakephp/bake": "^3.0", - "cakephp/cakephp": "^5.0.3", + "cakephp/bake": "dev-3.next", + "cakephp/cakephp": "dev-5.next as 5.1.0", "cakephp/cakephp-codesniffer": "^5.0", - "phpunit/phpunit": "^10.1.0" + "phpunit/phpunit": "^10.5.5 || ^11.1.3" }, "suggest": { "cakephp/bake": "If you want to generate migrations.", diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c046f594..3102234f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -112,6 +112,12 @@ + {$phpFile}"; + }, + $phpFiles + )]]> array_merge($versions, array_keys($migrations)) @@ -137,6 +143,10 @@ + + $messages + $messages + io->level()]]> @@ -144,6 +154,13 @@ self::VERBOSITY_* + + + $dropTables + $phinxTables + $tables + + regexpParseColumn]]> diff --git a/tests/TestCase/Command/BakeMigrationCommandTest.php b/tests/TestCase/Command/BakeMigrationCommandTest.php index a9484f6a..3413a387 100644 --- a/tests/TestCase/Command/BakeMigrationCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationCommandTest.php @@ -19,6 +19,7 @@ use Cake\TestSuite\StringCompareTrait; use Migrations\Command\BakeMigrationCommand; use Migrations\Test\TestCase\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * BakeMigrationCommandTest class @@ -86,9 +87,9 @@ public static function nameVariations() /** * Test the execute method. * - * @dataProvider nameVariations * @return void */ + #[DataProvider('nameVariations')] public function testCreate($name, $fileSuffix) { $this->exec("bake migration CreateUsers {$name} --connection test"); @@ -181,7 +182,6 @@ public function testAddPrimaryKeyToExistingUsersTable() } /** - * @covers \Migrations\Command\BakeMigrationCommand::detectAction() * @return void */ public function testDetectAction() diff --git a/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php b/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php index d4b8269b..2d0c5f04 100644 --- a/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php @@ -56,6 +56,7 @@ public function setUp(): void { parent::setUp(); + $this->loadPlugins(['SimpleSnapshot']); $this->_compareBasePath = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS; $this->migrationPath = ROOT . DS . 'config' . DS . 'Migrations' . DS; diff --git a/tests/TestCase/Command/MigrationCommandTest.php b/tests/TestCase/Command/MigrationCommandTest.php index 8cc9a209..acf13323 100644 --- a/tests/TestCase/Command/MigrationCommandTest.php +++ b/tests/TestCase/Command/MigrationCommandTest.php @@ -135,11 +135,11 @@ protected function getMockCommand($command) $mock->expects($this->any()) ->method('getOutput') - ->will($this->returnValue(new NullOutput())); + ->willReturn(new NullOutput()); $mock->expects($this->any()) ->method('getApp') - ->will($this->returnValue(new MigrationsDispatcher(PHINX_VERSION))); + ->willReturn(new MigrationsDispatcher(PHINX_VERSION)); return $mock; } diff --git a/tests/TestCase/Command/Phinx/MarkMigratedTest.php b/tests/TestCase/Command/Phinx/MarkMigratedTest.php index 003d3492..b01c7e54 100644 --- a/tests/TestCase/Command/Phinx/MarkMigratedTest.php +++ b/tests/TestCase/Command/Phinx/MarkMigratedTest.php @@ -154,9 +154,9 @@ public function testExecute() ->getMock(); $manager->expects($this->any()) - ->method('getEnvironment')->will($this->returnValue($env)); + ->method('getEnvironment')->willReturn($env); $manager->expects($this->any()) - ->method('getMigrations')->will($this->returnValue($migrations)); + ->method('getMigrations')->willReturn($migrations); $manager ->method('markMigrated')->will($this->throwException(new Exception('Error during marking process'))); diff --git a/tests/TestCase/Command/Phinx/SeedTest.php b/tests/TestCase/Command/Phinx/SeedTest.php index d80f77c1..f30d3b83 100644 --- a/tests/TestCase/Command/Phinx/SeedTest.php +++ b/tests/TestCase/Command/Phinx/SeedTest.php @@ -118,7 +118,7 @@ public function testExecute() $result = $this->connection->selectQuery() ->select(['*']) ->from('numbers') - ->order('id DESC') + ->orderBy('id DESC') ->limit(1) ->execute()->fetchAll('assoc'); $expected = [ @@ -160,7 +160,7 @@ public function testExecuteCustomParams() $result = $this->connection->selectQuery() ->select(['*']) ->from('numbers') - ->order('id DESC') + ->orderBy('id DESC') ->limit(1) ->execute()->fetchAll('assoc'); $expected = [ diff --git a/tests/TestCase/Config/AbstractConfigTestCase.php b/tests/TestCase/Config/AbstractConfigTestCase.php index 91091c20..de9ec7b4 100644 --- a/tests/TestCase/Config/AbstractConfigTestCase.php +++ b/tests/TestCase/Config/AbstractConfigTestCase.php @@ -7,8 +7,6 @@ /** * Class AbstractConfigTest - * - * @coversNothing */ abstract class AbstractConfigTestCase extends TestCase { diff --git a/tests/TestCase/Config/ConfigTest.php b/tests/TestCase/Config/ConfigTest.php index ada4bd41..ec9dfd9c 100644 --- a/tests/TestCase/Config/ConfigTest.php +++ b/tests/TestCase/Config/ConfigTest.php @@ -4,19 +4,14 @@ use InvalidArgumentException; use Migrations\Config\Config; +use PHPUnit\Framework\Attributes\DataProvider; use UnexpectedValueException; /** * Class ConfigTest - * - * @package Test\Phinx\Config - * @group config */ class ConfigTest extends AbstractConfigTestCase { - /** - * @covers \Phinx\Config\Config::getEnvironment - */ public function testGetEnvironmentMethod() { $config = new Config($this->getConfigArray()); @@ -33,12 +28,6 @@ public function testEnvironmentHasMigrationTable() $this->assertSame('test_table', $config->getEnvironment()['migration_table']); } - /** - * @covers \Phinx\Config\Config::offsetGet - * @covers \Phinx\Config\Config::offsetSet - * @covers \Phinx\Config\Config::offsetExists - * @covers \Phinx\Config\Config::offsetUnset - */ public function testArrayAccessMethods() { $config = new Config([]); @@ -49,9 +38,6 @@ public function testArrayAccessMethods() $this->assertArrayNotHasKey('foo', $config); } - /** - * @covers \Phinx\Config\Config::offsetGet - */ public function testUndefinedArrayAccess() { $config = new Config([]); @@ -62,46 +48,30 @@ public function testUndefinedArrayAccess() $config['foo']; } - /** - * @covers \Phinx\Config\Config::getMigrationBaseClassName - */ public function testGetMigrationBaseClassNameGetsDefaultBaseClass() { $config = new Config([]); $this->assertEquals('AbstractMigration', $config->getMigrationBaseClassName()); } - /** - * @covers \Phinx\Config\Config::getMigrationBaseClassName - */ public function testGetMigrationBaseClassNameGetsDefaultBaseClassWithNamespace() { $config = new Config([]); $this->assertEquals('Phinx\Migration\AbstractMigration', $config->getMigrationBaseClassName(false)); } - /** - * @covers \Phinx\Config\Config::getMigrationBaseClassName - */ public function testGetMigrationBaseClassNameGetsAlternativeBaseClass() { $config = new Config(['migration_base_class' => 'Phinx\Migration\AlternativeAbstractMigration']); $this->assertEquals('AlternativeAbstractMigration', $config->getMigrationBaseClassName()); } - /** - * @covers \Phinx\Config\Config::getMigrationBaseClassName - */ public function testGetMigrationBaseClassNameGetsAlternativeBaseClassWithNamespace() { $config = new Config(['migration_base_class' => 'Phinx\Migration\AlternativeAbstractMigration']); $this->assertEquals('Phinx\Migration\AlternativeAbstractMigration', $config->getMigrationBaseClassName(false)); } - /** - * @covers \Phinx\Config\Config::getTemplateFile - * @covers \Phinx\Config\Config::getTemplateClass - */ public function testGetTemplateValuesFalseOnEmpty() { $config = new Config([]); @@ -118,9 +88,6 @@ public function testGetSeedPath() $this->assertEquals('db/seeds1', $config->getSeedPath()); } - /** - * @covers \Phinx\Config\Config::getSeedPaths - */ public function testGetSeedPathThrowsException() { $config = new Config([]); @@ -134,8 +101,6 @@ public function testGetSeedPathThrowsException() /** * Checks if base class is returned correctly when specified without * a namespace. - * - * @covers \Phinx\Config\Config::getMigrationBaseClassName */ public function testGetMigrationBaseClassNameNoNamespace() { @@ -146,8 +111,6 @@ public function testGetMigrationBaseClassNameNoNamespace() /** * Checks if base class is returned correctly when specified without * a namespace. - * - * @covers \Phinx\Config\Config::getMigrationBaseClassName */ public function testGetMigrationBaseClassNameNoNamespaceNoDrop() { @@ -155,9 +118,6 @@ public function testGetMigrationBaseClassNameNoNamespaceNoDrop() $this->assertEquals('BaseMigration', $config->getMigrationBaseClassName(false)); } - /** - * @covers \Phinx\Config\Config::getVersionOrder - */ public function testGetVersionOrder() { $config = new Config([]); @@ -165,10 +125,7 @@ public function testGetVersionOrder() $this->assertEquals(Config::VERSION_ORDER_EXECUTION_TIME, $config->getVersionOrder()); } - /** - * @covers \Phinx\Config\Config::isVersionOrderCreationTime - * @dataProvider isVersionOrderCreationTimeDataProvider - */ + #[DataProvider('isVersionOrderCreationTimeDataProvider')] public function testIsVersionOrderCreationTime($versionOrder, $expected) { // get config stub @@ -179,14 +136,11 @@ public function testIsVersionOrderCreationTime($versionOrder, $expected) $configStub->expects($this->once()) ->method('getVersionOrder') - ->will($this->returnValue($versionOrder)); + ->willReturn($versionOrder); $this->assertEquals($expected, $configStub->isVersionOrderCreationTime()); } - /** - * @covers \Phinx\Config\Config::isVersionOrderCreationTime - */ public static function isVersionOrderCreationTimeDataProvider() { return [ @@ -216,9 +170,7 @@ public static function templateStyleDataProvider(): array ]; } - /** - * @dataProvider templateStyleDataProvider - */ + #[DataProvider('templateStyleDataProvider')] public function testTemplateStyle(string $style, string $expected): void { $config = new Config(['templates' => ['style' => $style]]); diff --git a/tests/TestCase/ConfigurationTraitTest.php b/tests/TestCase/ConfigurationTraitTest.php index 39978328..51267f6f 100644 --- a/tests/TestCase/ConfigurationTraitTest.php +++ b/tests/TestCase/ConfigurationTraitTest.php @@ -277,12 +277,10 @@ protected function _getCommandMock(string $migrationsPath, string $seedsPath): E $command->setInput($input); $command->expects($this->any()) ->method('getOperationsPath') - ->will( - $this->returnValueMap([ - [$input, 'Migrations', $migrationsPath], - [$input, 'Seeds', $seedsPath], - ]) - ); + ->willReturnMap([ + [$input, 'Migrations', $migrationsPath], + [$input, 'Seeds', $seedsPath], + ]); return $command; } diff --git a/tests/TestCase/Db/Adapter/AdapterFactoryTest.php b/tests/TestCase/Db/Adapter/AdapterFactoryTest.php index 6fc41e16..7aa7a528 100644 --- a/tests/TestCase/Db/Adapter/AdapterFactoryTest.php +++ b/tests/TestCase/Db/Adapter/AdapterFactoryTest.php @@ -5,6 +5,7 @@ use Migrations\Db\Adapter\AdapterFactory; use Migrations\Db\Adapter\PdoAdapter; +use Migrations\Test\TestCase\Db\Adapter\DefaultPdoAdapterTrait; use PHPUnit\Framework\TestCase; use ReflectionMethod; use RuntimeException; @@ -33,14 +34,16 @@ public function testInstanceIsFactory() public function testRegisterAdapter() { - $mock = $this->getMockForAbstractClass(PdoAdapter::class, [['foo' => 'bar']]); - $this->factory->registerAdapter('test', function (array $options) use ($mock) { + $pdo = new class (['foo' => 'bar']) extends PdoAdapter { + use DefaultPdoAdapterTrait; + }; + $this->factory->registerAdapter('test', function (array $options) use ($pdo) { $this->assertEquals('value', $options['key']); - return $mock; + return $pdo; }); - $this->assertEquals($mock, $this->factory->getAdapter('test', ['key' => 'value'])); + $this->assertEquals($pdo, $this->factory->getAdapter('test', ['key' => 'value'])); } public function testRegisterAdapterFailure() diff --git a/tests/TestCase/Db/Adapter/DefaultPdoAdapterTrait.php b/tests/TestCase/Db/Adapter/DefaultPdoAdapterTrait.php new file mode 100644 index 00000000..365be029 --- /dev/null +++ b/tests/TestCase/Db/Adapter/DefaultPdoAdapterTrait.php @@ -0,0 +1,180 @@ +assertFalse($this->adapter->hasColumn('ntable', 'address')); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testUnsignedPksFeatureFlag() { $this->adapter->connect(); @@ -484,9 +483,7 @@ public function testUnsignedPksFeatureFlag() $this->assertTrue($columns[0]->getSigned()); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testAddTimestampsFeatureFlag() { Configure::write('Migrations.add_timestamps_use_datetime', true); @@ -751,9 +748,7 @@ public static function integerDataProvider() ]; } - /** - * @dataProvider integerDataProvider - */ + #[DataProvider('integerDataProvider')] public function testIntegerColumnTypes($phinx_type, $options, $sql_type, $width, $extra) { $table = new Table('table1', [], $this->adapter); @@ -973,9 +968,9 @@ public static function sqlTypeIntConversionProvider() } /** - * @dataProvider sqlTypeIntConversionProvider * The second argument is not typed as MysqlAdapter::INT_BIG is a float, and all other values are integers */ + #[DataProvider('sqlTypeIntConversionProvider')] public function testGetSqlTypeIntegerConversion(string $type, $limit, string $expectedType, int $expectedLimit) { $sqlType = $this->adapter->getSqlType($type, $limit); @@ -1028,7 +1023,7 @@ public static function binaryToBlobAutomaticConversionData() ]; } - /** @dataProvider binaryToBlobAutomaticConversionData */ + #[DataProvider('binaryToBlobAutomaticConversionData')] public function testBinaryToBlobAutomaticConversion(?int $limit, string $expectedType, int $expectedLimit) { $table = new Table('t', [], $this->adapter); @@ -1055,7 +1050,7 @@ public static function varbinaryToBlobAutomaticConversionData() ]; } - /** @dataProvider varbinaryToBlobAutomaticConversionData */ + #[DataProvider('varbinaryToBlobAutomaticConversionData')] public function testVarbinaryToBlobAutomaticConversion(?int $limit, string $expectedType, int $expectedLimit) { $table = new Table('t', [], $this->adapter); @@ -1097,7 +1092,7 @@ public static function blobColumnsData() ]; } - /** @dataProvider blobColumnsData */ + #[DataProvider('blobColumnsData')] public function testblobColumns(string $type, string $expectedType, ?int $limit, int $expectedLimit) { $table = new Table('t', [], $this->adapter); @@ -1278,9 +1273,7 @@ public static function columnsProvider() ]; } - /** - * @dataProvider columnsProvider - */ + #[DataProvider('columnsProvider')] public function testGetColumns($colName, $type, $options) { $table = new Table('t', [], $this->adapter); @@ -1698,9 +1691,9 @@ public static function nonExistentForeignKeyColumnsProvider(): array } /** - * @dataProvider nonExistentForeignKeyColumnsProvider * @param array $columns */ + #[DataProvider('nonExistentForeignKeyColumnsProvider')] public function testDropForeignKeyByNonExistentKeyColumns(array $columns) { $refTable = new Table('ref_table', [], $this->adapter); @@ -1789,9 +1782,7 @@ public function testDropForeignKeyAsString() $this->assertFalse($this->adapter->hasForeignKey($table->getName(), ['ref_table_id'])); } - /** - * @dataProvider provideForeignKeysToCheck - */ + #[DataProvider('provideForeignKeysToCheck')] public function testHasForeignKey($tableDef, $key, $exp) { $conn = $this->adapter->getConnection(); @@ -2207,7 +2198,7 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_INSERT); + $builder = $this->adapter->getInsertBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) ->into('table1') @@ -2217,7 +2208,7 @@ public function testQueryBuilder() $this->assertEquals(2, $stm->rowCount()); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_SELECT); + $builder = $this->adapter->getSelectBuilder(); $stm = $builder ->select('*') ->from('table1') @@ -2230,7 +2221,7 @@ public function testQueryBuilder() $stm->fetch('assoc') ); - $builder = $this->adapter->getQueryBuilder(query::TYPE_DELETE); + $builder = $this->adapter->getDeleteBuilder(); $stm = $builder ->delete('table1') ->where(['int_col <' => 2]) @@ -2293,10 +2284,10 @@ public static function geometryTypeProvider() } /** - * @dataProvider geometryTypeProvider * @param string $type * @param string $geom */ + #[DataProvider('geometryTypeProvider')] public function testGeometrySridSupport($type, $geom) { $this->adapter->connect(); @@ -2317,10 +2308,10 @@ public function testGeometrySridSupport($type, $geom) } /** - * @dataProvider geometryTypeProvider * @param string $type * @param string $geom */ + #[DataProvider('geometryTypeProvider')] public function testGeometrySridThrowsInsertDifferentSrid($type, $geom) { $this->adapter->connect(); @@ -2374,10 +2365,10 @@ public static function defaultsCastAsExpressions() * MySQL 8 added support for specifying defaults for the BLOB, TEXT, GEOMETRY, and JSON data types, * however requiring that they be wrapped in expressions. * - * @dataProvider defaultsCastAsExpressions * @param string $type * @param string $default */ + #[DataProvider('defaultsCastAsExpressions')] public function testDefaultsCastAsExpressionsForCertainTypes(string $type, string $default): void { $this->adapter->connect(); @@ -2443,9 +2434,7 @@ public static function integerDataTypesSQLProvider() ]; } - /** - * @dataProvider integerDataTypesSQLProvider - */ + #[DataProvider('integerDataTypesSQLProvider')] public function testGetPhinxTypeFromSQLDefinition(string $sqlDefinition, array $expectedResponse) { $result = $this->adapter->getPhinxType($sqlDefinition); diff --git a/tests/TestCase/Db/Adapter/PdoAdapterTest.php b/tests/TestCase/Db/Adapter/PdoAdapterTest.php index cb3bfdd5..d3c70e29 100644 --- a/tests/TestCase/Db/Adapter/PdoAdapterTest.php +++ b/tests/TestCase/Db/Adapter/PdoAdapterTest.php @@ -3,8 +3,11 @@ namespace Migrations\Test\Db\Adapter; +use Migrations\Db\Adapter\PdoAdapter; +use Migrations\Test\TestCase\Db\Adapter\DefaultPdoAdapterTrait; use PDOException; use Phinx\Config\Config; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -17,7 +20,9 @@ class PdoAdapterTest extends TestCase protected function setUp(): void { - $this->adapter = $this->getMockForAbstractClass('\Migrations\Db\Adapter\PdoAdapter', [['foo' => 'bar']]); + $this->adapter = new class (['foo' => 'bar', 'version_order' => Config::VERSION_ORDER_CREATION_TIME]) extends PdoAdapter { + use DefaultPdoAdapterTrait; + }; } protected function tearDown(): void @@ -46,45 +51,36 @@ public function testSchemaTableName() $this->assertEquals('schema_table_test', $this->adapter->getSchemaTableName()); } - /** - * @dataProvider getVersionLogDataProvider - */ + #[DataProvider('getVersionLogDataProvider')] public function testGetVersionLog($versionOrder, $expectedOrderBy) { - $adapter = $this->getMockForAbstractClass( - '\Migrations\Db\Adapter\PdoAdapter', - [['version_order' => $versionOrder]], - '', - true, - true, - true, - ['fetchAll', 'getSchemaTableName', 'quoteTableName'] - ); - - $schemaTableName = 'log'; - $adapter->expects($this->once()) - ->method('getSchemaTableName') - ->will($this->returnValue($schemaTableName)); - $adapter->expects($this->once()) - ->method('quoteTableName') - ->with($schemaTableName) - ->will($this->returnValue("'$schemaTableName'")); - - $mockRows = [ - [ - 'version' => '20120508120534', - 'key' => 'value', - ], - [ - 'version' => '20130508120534', - 'key' => 'value', - ], - ]; - - $adapter->expects($this->once()) - ->method('fetchAll') - ->with("SELECT * FROM '$schemaTableName' ORDER BY $expectedOrderBy") - ->will($this->returnValue($mockRows)); + $adapter = new class (['version_order' => $versionOrder]) extends PdoAdapter { + use DefaultPdoAdapterTrait; + + public function getSchemaTableName(): string + { + return 'log'; + } + + public function quoteTableName(string $tableName): string + { + return "'$tableName'"; + } + + public function fetchAll(string $sql): array + { + return [ + [ + 'version' => '20120508120534', + 'key' => 'value', + ], + [ + 'version' => '20130508120534', + 'key' => 'value', + ], + ]; + } + }; // we expect the mock rows but indexed by version creation time $expected = [ @@ -116,10 +112,9 @@ public static function getVersionLogDataProvider() public function testGetVersionLogInvalidVersionOrderKO() { $this->expectExceptionMessage('Invalid version_order configuration option'); - $adapter = $this->getMockForAbstractClass( - '\Migrations\Db\Adapter\PdoAdapter', - [['version_order' => 'invalid']] - ); + $adapter = new class (['version_order' => 'invalid']) extends PdoAdapter { + use DefaultPdoAdapterTrait; + }; $this->expectException(RuntimeException::class); @@ -128,32 +123,24 @@ public function testGetVersionLogInvalidVersionOrderKO() public function testGetVersionLongDryRun() { - $adapter = $this->getMockForAbstractClass( - '\Migrations\Db\Adapter\PdoAdapter', - [['version_order' => Config::VERSION_ORDER_CREATION_TIME]], - '', - true, - true, - true, - ['isDryRunEnabled', 'fetchAll', 'getSchemaTableName', 'quoteTableName'] - ); - - $schemaTableName = 'log'; - - $adapter->expects($this->once()) - ->method('isDryRunEnabled') - ->will($this->returnValue(true)); - $adapter->expects($this->once()) - ->method('getSchemaTableName') - ->will($this->returnValue($schemaTableName)); - $adapter->expects($this->once()) - ->method('quoteTableName') - ->with($schemaTableName) - ->will($this->returnValue("'$schemaTableName'")); - $adapter->expects($this->once()) - ->method('fetchAll') - ->with("SELECT * FROM '$schemaTableName' ORDER BY version ASC") - ->will($this->throwException(new PDOException())); + $adapter = new class (['version_order' => Config::VERSION_ORDER_CREATION_TIME]) extends PdoAdapter { + use DefaultPdoAdapterTrait; + + public function isDryRunEnabled(): bool + { + return true; + } + + public function getSchemaTableName(): string + { + return 'log'; + } + + public function fetchAll(string $sql): array + { + throw new PDOException(); + } + }; $this->assertEquals([], $adapter->getVersionLog()); } diff --git a/tests/TestCase/Db/Adapter/PhinxAdapterTest.php b/tests/TestCase/Db/Adapter/PhinxAdapterTest.php index e4e66315..58038ff1 100644 --- a/tests/TestCase/Db/Adapter/PhinxAdapterTest.php +++ b/tests/TestCase/Db/Adapter/PhinxAdapterTest.php @@ -18,6 +18,7 @@ use Phinx\Db\Table as PhinxTable; use Phinx\Db\Table\Column as PhinxColumn; use Phinx\Util\Literal as PhinxLiteral; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -643,9 +644,6 @@ public function testChangeColumnDefaultValue() $this->assertEquals("'test1'", $rows[1]['dflt_value']); } - /** - * @group bug922 - */ public function testChangeColumnWithForeignKey() { $refTable = new PhinxTable('ref_table', [], $this->adapter); @@ -1485,9 +1483,6 @@ public function testLiteralSupport() $this->assertEquals(Literal::from('decimal'), array_pop($columns)->getType()); } - /** - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasPrimaryKey - */ public function testHasNamedPrimaryKey() { $this->expectException(InvalidArgumentException::class); @@ -1495,7 +1490,6 @@ public function testHasNamedPrimaryKey() $this->adapter->hasPrimaryKey('t', [], 'named_constraint'); } - /** @covers \Migrations\Db\Adapter\SqliteAdapter::getColumnTypes */ public function testGetColumnTypes() { $columnTypes = $this->adapter->getColumnTypes(); @@ -1529,10 +1523,7 @@ public function testGetColumnTypes() $this->assertEquals($expected, $columnTypes); } - /** - * @dataProvider provideColumnTypesForValidation - * @covers \Phinx\Db\Adapter\SqliteAdapter::isValidColumnType - */ + #[DataProvider('provideColumnTypesForValidation')] public function testIsValidColumnType($phinxType, $exp) { $col = (new PhinxColumn())->setType($phinxType); @@ -1579,10 +1570,6 @@ public static function provideColumnTypesForValidation() ]; } - /** @covers \Phinx\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Phinx\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Phinx\Db\Adapter\SqliteAdapter::getColumns - */ public function testGetColumns() { $conn = $this->adapter->getConnection(); diff --git a/tests/TestCase/Db/Adapter/PostgresAdapterTest.php b/tests/TestCase/Db/Adapter/PostgresAdapterTest.php index 5b939603..04205c78 100644 --- a/tests/TestCase/Db/Adapter/PostgresAdapterTest.php +++ b/tests/TestCase/Db/Adapter/PostgresAdapterTest.php @@ -7,7 +7,6 @@ use Cake\Console\TestSuite\StubConsoleInput; use Cake\Console\TestSuite\StubConsoleOutput; use Cake\Database\Connection; -use Cake\Database\Query; use Cake\Datasource\ConnectionManager; use InvalidArgumentException; use Migrations\Db\Adapter\AbstractAdapter; @@ -18,6 +17,8 @@ use Migrations\Db\Table; use Migrations\Db\Table\Column; use PDO; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; class PostgresAdapterTest extends TestCase @@ -557,9 +558,7 @@ public static function providerAddColumnIdentity(): array ]; } - /** - * @dataProvider providerAddColumnIdentity - */ + #[DataProvider('providerAddColumnIdentity')] public function testAddColumnIdentity($generated, $addToColumn) { if (!$this->usingPostgres10()) { @@ -653,9 +652,7 @@ public static function providerIgnoresLimit(): array ]; } - /** - * @dataProvider providerIgnoresLimit - */ + #[DataProvider('providerIgnoresLimit')] public function testAddColumnIgnoresLimit(string $column_type, ?string $actual_type = null): void { $table = new Table('table1', [], $this->adapter); @@ -823,9 +820,7 @@ public static function providerArrayType() ]; } - /** - * @dataProvider providerArrayType - */ + #[DataProvider('providerArrayType')] public function testAddColumnArrayType($column_name, $column_type) { $table = new Table('table1', [], $this->adapter); @@ -904,9 +899,7 @@ public static function providerChangeColumnIdentity(): array ]; } - /** - * @dataProvider providerChangeColumnIdentity - */ + #[DataProvider('providerChangeColumnIdentity')] public function testChangeColumnIdentity($generated) { if (!$this->usingPostgres10()) { @@ -971,9 +964,7 @@ public static function integersProvider() ]; } - /** - * @dataProvider integersProvider - */ + #[DataProvider('integersProvider')] public function testChangeColumnFromTextToInteger($type, $value) { $table = new Table('t', [], $this->adapter); @@ -1131,9 +1122,7 @@ public static function columnsProvider() ]; } - /** - * @dataProvider columnsProvider - */ + #[DataProvider('columnsProvider')] public function testGetColumns($colName, $type, $options, $actualType = null) { $table = new Table('t', [], $this->adapter); @@ -1154,9 +1143,7 @@ public function testGetColumns($colName, $type, $options, $actualType = null) } } - /** - * @dataProvider columnsProvider - */ + #[DataProvider('columnsProvider')] public function testGetColumnsWithSchema($colName, $type, $options, $actualType = null) { $this->adapter->createSchema('tschema'); @@ -1615,9 +1602,9 @@ public static function nonExistentForeignKeyColumnsProvider(): array } /** - * @dataProvider nonExistentForeignKeyColumnsProvider * @param array $columns */ + #[DataProvider('nonExistentForeignKeyColumnsProvider')] public function testDropForeignKeyByNonExistentKeyColumns(array $columns) { $refTable = new Table('ref_table', [], $this->adapter); @@ -1683,9 +1670,7 @@ public function testDropForeignKeyByName() $this->assertFalse($this->adapter->hasForeignKey($table->getName(), ['ref_table_id'])); } - /** - * @dataProvider provideForeignKeysToCheck - */ + #[DataProvider('provideForeignKeysToCheck')] public function testHasForeignKey($tableDef, $key, $exp) { $conn = $this->adapter->getConnection(); @@ -1934,9 +1919,7 @@ public function testCanAddCommentForColumnWithReservedName() ); } - /** - * @depends testCanAddColumnComment - */ + #[Depends('testCanAddColumnComment')] public function testCanChangeColumnComment() { $table = new Table('table1', [], $this->adapter); @@ -1963,9 +1946,7 @@ public function testCanChangeColumnComment() $this->assertEquals($comment, $row['column_comment'], 'Dont change column comment correctly'); } - /** - * @depends testCanAddColumnComment - */ + #[Depends('testCanAddColumnComment')] public function testCanRemoveColumnComment() { $table = new Table('table1', [], $this->adapter); @@ -1989,9 +1970,7 @@ public function testCanRemoveColumnComment() $this->assertEmpty($row['column_comment'], 'Dont remove column comment correctly'); } - /** - * @depends testCanAddColumnComment - */ + #[Depends('testCanAddColumnComment')] public function testCanAddMultipleCommentsToOneTable() { $table = new Table('table1', [], $this->adapter); @@ -2030,9 +2009,7 @@ public function testCanAddMultipleCommentsToOneTable() $this->assertEquals($comment2, $row['column_comment'], 'Could not create second column comment'); } - /** - * @depends testCanAddColumnComment - */ + #[Depends('testCanAddColumnComment')] public function testColumnsAreResetBetweenTables() { $table = new Table('widgets', [], $this->adapter); @@ -2593,7 +2570,7 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_INSERT); + $builder = $this->adapter->getInsertBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) ->into('table1') @@ -2603,7 +2580,7 @@ public function testQueryBuilder() $this->assertEquals(2, $stm->rowCount()); - $builder = $this->adapter->getQueryBuilder(query::TYPE_SELECT); + $builder = $this->adapter->getSelectBuilder(); $stm = $builder ->select('*') ->from('table1') @@ -2616,7 +2593,7 @@ public function testQueryBuilder() $stm->fetch('assoc') ); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_DELETE); + $builder = $this->adapter->getDeleteBuilder(); $stm = $builder ->delete('table1') ->where(['int_col <' => 2]) @@ -2687,9 +2664,7 @@ public static function serialProvider(): array ]; } - /** - * @dataProvider serialProvider - */ + #[DataProvider('serialProvider')] public function testSerialAliases(string $columnType): void { $table = new Table('test', ['id' => false], $this->adapter); diff --git a/tests/TestCase/Db/Adapter/RecordingAdapterTest.php b/tests/TestCase/Db/Adapter/RecordingAdapterTest.php index b1c85000..7db2af0d 100644 --- a/tests/TestCase/Db/Adapter/RecordingAdapterTest.php +++ b/tests/TestCase/Db/Adapter/RecordingAdapterTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $stub->expects($this->any()) ->method('isValidColumnType') - ->will($this->returnValue(true)); + ->willReturn(true); $this->adapter = new RecordingAdapter($stub); } @@ -63,7 +63,7 @@ public function testRecordingAdapterCanInvertAddColumn() ->getAdapter() ->expects($this->any()) ->method('hasTable') - ->will($this->returnValue(true)); + ->willReturn(true); $this->adapter ->getAdapter() @@ -92,7 +92,7 @@ public function testRecordingAdapterCanInvertRenameColumn() ->getAdapter() ->expects($this->any()) ->method('hasTable') - ->will($this->returnValue(true)); + ->willReturn(true); $table = new Table('atable', [], $this->adapter); $table->renameColumn('oldname', 'newname') @@ -110,7 +110,7 @@ public function testRecordingAdapterCanInvertAddIndex() ->getAdapter() ->expects($this->any()) ->method('hasTable') - ->will($this->returnValue(true)); + ->willReturn(true); $table = new Table('atable', [], $this->adapter); $table->addIndex(['email']) @@ -128,7 +128,7 @@ public function testRecordingAdapterCanInvertAddForeignKey() ->getAdapter() ->expects($this->any()) ->method('hasTable') - ->will($this->returnValue(true)); + ->willReturn(true); $table = new Table('atable', [], $this->adapter); $table->addForeignKey(['ref_table_id'], 'refTable') @@ -146,7 +146,7 @@ public function testGetInvertedCommandsThrowsExceptionForIrreversibleCommand() ->getAdapter() ->expects($this->any()) ->method('hasTable') - ->will($this->returnValue(true)); + ->willReturn(true); $table = new Table('atable', [], $this->adapter); $table->removeColumn('thing') diff --git a/tests/TestCase/Db/Adapter/SqliteAdapterTest.php b/tests/TestCase/Db/Adapter/SqliteAdapterTest.php index 593c1d49..6a779357 100644 --- a/tests/TestCase/Db/Adapter/SqliteAdapterTest.php +++ b/tests/TestCase/Db/Adapter/SqliteAdapterTest.php @@ -8,7 +8,6 @@ use Cake\Console\TestSuite\StubConsoleInput; use Cake\Console\TestSuite\StubConsoleOutput; use Cake\Database\Connection; -use Cake\Database\Query; use Cake\Datasource\ConnectionManager; use Exception; use InvalidArgumentException; @@ -20,6 +19,7 @@ use Migrations\Db\Table\Column; use Migrations\Db\Table\ForeignKey; use PDOException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionObject; use RuntimeException; @@ -512,9 +512,7 @@ public static function irregularCreateTableProvider() ]; } - /** - * @dataProvider irregularCreateTableProvider - */ + #[DataProvider('irregularCreateTableProvider')] public function testAddColumnToIrregularCreateTableStatements(string $createTableSql, array $expectedColumns): void { $this->adapter->execute($createTableSql); @@ -761,10 +759,10 @@ public static function customIndexSQLDataProvider(): array } /** - * @dataProvider customIndexSQLDataProvider * @param string $indexSQL Index creation SQL * @param string $newIndexSQL Expected new index creation SQL */ + #[DataProvider('customIndexSQLDataProvider')] public function testRenameColumnWithCustomIndex(string $indexSQL, string $newIndexSQL) { $table = new Table('t', [], $this->adapter); @@ -860,10 +858,10 @@ public static function customCompositeIndexSQLDataProvider(): array * Index SQL is mostly returned as-is, hence custom indices can contain * a wide variety of formats. * - * @dataProvider customCompositeIndexSQLDataProvider * @param string $indexSQL Index creation SQL * @param string $newIndexSQL Expected new index creation SQL */ + #[DataProvider('customCompositeIndexSQLDataProvider')] public function testRenameColumnWithCustomCompositeIndex(string $indexSQL, string $newIndexSQL) { $table = new Table('t', [], $this->adapter); @@ -922,9 +920,6 @@ public function testChangeColumnDefaultValue() $this->assertEquals("'test1'", $rows[1]['dflt_value']); } - /** - * @group bug922 - */ public function testChangeColumnWithForeignKey() { $refTable = new Table('ref_table', [], $this->adapter); @@ -1039,9 +1034,7 @@ public function testChangeColumnWithCommasInCommentsOrDefaultValue() $this->assertEquals('another default', (string)$cols[1]->getDefault()); } - /** - * @dataProvider columnCreationArgumentProvider - */ + #[DataProvider('columnCreationArgumentProvider')] public function testDropColumn($columnCreationArgs) { $table = new Table('t', [], $this->adapter); @@ -1163,9 +1156,9 @@ public function testDropColumnWithExpressionIndex() } /** - * @dataProvider customIndexSQLDataProvider * @param string $indexSQL Index creation SQL */ + #[DataProvider('customIndexSQLDataProvider')] public function testDropColumnWithCustomIndex(string $indexSQL) { $table = new Table('t', [], $this->adapter); @@ -1183,9 +1176,9 @@ public function testDropColumnWithCustomIndex(string $indexSQL) } /** - * @dataProvider customCompositeIndexSQLDataProvider * @param string $indexSQL Index creation SQL */ + #[DataProvider('customCompositeIndexSQLDataProvider')] public function testDropColumnWithCustomCompositeIndex(string $indexSQL) { $table = new Table('t', [], $this->adapter); @@ -1509,9 +1502,9 @@ public static function nonExistentForeignKeyColumnsProvider(): array } /** - * @dataProvider nonExistentForeignKeyColumnsProvider * @param array $columns */ + #[DataProvider('nonExistentForeignKeyColumnsProvider')] public function testDropForeignKeyByNonExistentKeyColumns(array $columns) { $refTable = new Table('ref_table', [], $this->adapter); @@ -1914,7 +1907,7 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_INSERT); + $builder = $this->adapter->getInsertBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) ->into('table1') @@ -1924,7 +1917,7 @@ public function testQueryBuilder() $this->assertEquals(2, $stm->rowCount()); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_SELECT); + $builder = $this->adapter->getSelectBuilder(); $stm = $builder ->select('*') ->from('table1') @@ -1937,7 +1930,7 @@ public function testQueryBuilder() $stm->fetch('assoc') ); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_DELETE); + $builder = $this->adapter->getDeleteBuilder(); $stm = $builder ->delete('table1') ->where(['int_col <' => 2]) @@ -2264,13 +2257,7 @@ public function testLiteralSupport() $this->assertEquals(Literal::from('decimal'), array_pop($columns)->getType()); } - /** - * @dataProvider provideTableNamesForPresenceCheck - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasTable - * @covers \Migrations\Db\Adapter\SqliteAdapter::resolveTable - * @covers \Migrations\Db\Adapter\SqliteAdapter::quoteString - * @covers \Migrations\Db\Adapter\SqliteAdapter::getSchemaName - */ + #[DataProvider('provideTableNamesForPresenceCheck')] public function testHasTable($createName, $tableName, $exp) { // Test case for issue #1535 @@ -2316,14 +2303,7 @@ public static function provideTableNamesForPresenceCheck() ]; } - /** - * @dataProvider provideIndexColumnsToCheck - * @covers \Migrations\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Migrations\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Migrations\Db\Adapter\SqliteAdapter::getIndexes - * @covers \Migrations\Db\Adapter\SqliteAdapter::resolveIndex - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasIndex - */ + #[DataProvider('provideIndexColumnsToCheck')] public function testHasIndex($tableDef, $cols, $exp) { $conn = $this->adapter->getConnection(); @@ -2362,13 +2342,7 @@ public static function provideIndexColumnsToCheck() ]; } - /** - * @dataProvider provideIndexNamesToCheck - * @covers \Migrations\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Migrations\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Migrations\Db\Adapter\SqliteAdapter::getIndexes - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasIndexByName - */ + #[DataProvider('provideIndexNamesToCheck')] public function testHasIndexByName($tableDef, $index, $exp) { $conn = $this->adapter->getConnection(); @@ -2399,13 +2373,7 @@ public static function provideIndexNamesToCheck() ]; } - /** - * @dataProvider providePrimaryKeysToCheck - * @covers \Migrations\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Migrations\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasPrimaryKey - * @covers \Migrations\Db\Adapter\SqliteAdapter::getPrimaryKey - */ + #[DataProvider('providePrimaryKeysToCheck')] public function testHasPrimaryKey($tableDef, $key, $exp) { $this->assertFalse($this->adapter->hasTable('t'), 'Dirty test fixture'); @@ -2465,9 +2433,6 @@ public static function providePrimaryKeysToCheck() ]; } - /** - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasPrimaryKey - */ public function testHasNamedPrimaryKey() { $this->expectException(InvalidArgumentException::class); @@ -2475,13 +2440,7 @@ public function testHasNamedPrimaryKey() $this->adapter->hasPrimaryKey('t', [], 'named_constraint'); } - /** - * @dataProvider provideForeignKeysToCheck - * @covers \Migrations\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Migrations\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Migrations\Db\Adapter\SqliteAdapter::hasForeignKey - * @covers \Migrations\Db\Adapter\SqliteAdapter::getForeignKeys - */ + #[DataProvider('provideForeignKeysToCheck')] public function testHasForeignKey($tableDef, $key, $exp) { $conn = $this->adapter->getConnection(); @@ -2528,7 +2487,6 @@ public static function provideForeignKeysToCheck() ]; } - /** @covers \Migrations\Db\Adapter\SqliteAdapter::hasForeignKey */ public function testHasNamedForeignKey() { $refTable = new Table('tbl_parent_1', [], $this->adapter); @@ -2581,10 +2539,7 @@ public function testHasNamedForeignKey() $this->assertFalse($this->adapter->hasForeignKey('tbl_child', [], 'check_constraint_2')); } - /** - * @dataProvider providePhinxTypes - * @covers \Migrations\Db\Adapter\SqliteAdapter::getSqlType - */ + #[DataProvider('providePhinxTypes')] public function testGetSqlType($phinxType, $limit, $exp) { if ($exp instanceof Exception) { @@ -2640,10 +2595,7 @@ public static function providePhinxTypes() ]; } - /** - * @dataProvider provideSqlTypes - * @covers \Migrations\Db\Adapter\SqliteAdapter::getPhinxType - */ + #[DataProvider('provideSqlTypes')] public function testGetPhinxType($sqlType, $exp) { $this->assertEquals($exp, $this->adapter->getPhinxType($sqlType)); @@ -2821,7 +2773,6 @@ public static function provideSqlTypes() ]; } - /** @covers \Migrations\Db\Adapter\SqliteAdapter::getColumnTypes */ public function testGetColumnTypes() { $columnTypes = $this->adapter->getColumnTypes(); @@ -2855,10 +2806,7 @@ public function testGetColumnTypes() $this->assertEquals($expected, $columnTypes); } - /** - * @dataProvider provideColumnTypesForValidation - * @covers \Phinx\Db\Adapter\SqliteAdapter::isValidColumnType - */ + #[DataProvider('provideColumnTypesForValidation')] public function testIsValidColumnType($phinxType, $exp) { $col = (new Column())->setType($phinxType); @@ -2905,10 +2853,7 @@ public static function provideColumnTypesForValidation() ]; } - /** - * @dataProvider provideDatabaseVersionStrings - * @covers \Phinx\Db\Adapter\SqliteAdapter::databaseVersionAtLeast - */ + #[DataProvider('provideDatabaseVersionStrings')] public function testDatabaseVersionAtLeast($ver, $exp) { $this->assertSame($exp, $this->adapter->databaseVersionAtLeast($ver)); @@ -2927,12 +2872,7 @@ public static function provideDatabaseVersionStrings() ]; } - /** - * @dataProvider provideColumnNamesToCheck - * @covers \Phinx\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Phinx\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Phinx\Db\Adapter\SqliteAdapter::hasColumn - */ + #[DataProvider('provideColumnNamesToCheck')] public function testHasColumn($tableDef, $col, $exp) { $conn = $this->adapter->getConnection(); @@ -2970,10 +2910,6 @@ public static function provideColumnNamesToCheck() ]; } - /** @covers \Phinx\Db\Adapter\SqliteAdapter::getSchemaName - * @covers \Phinx\Db\Adapter\SqliteAdapter::getTableInfo - * @covers \Phinx\Db\Adapter\SqliteAdapter::getColumns - */ public function testGetColumns() { $conn = $this->adapter->getConnection(); @@ -2997,10 +2933,7 @@ public function testGetColumns() } } - /** - * @dataProvider provideIdentityCandidates - * @covers \Phinx\Db\Adapter\SqliteAdapter::resolveIdentity - */ + #[DataProvider('provideIdentityCandidates')] public function testGetColumnsForIdentity($tableDef, $exp) { $conn = $this->adapter->getConnection(); @@ -3029,10 +2962,7 @@ public static function provideIdentityCandidates() ]; } - /** - * @dataProvider provideDefaultValues - * @covers \Phinx\Db\Adapter\SqliteAdapter::parseDefaultValue - */ + #[DataProvider('provideDefaultValues')] public function testGetColumnsForDefaults($tableDef, $exp) { $conn = $this->adapter->getConnection(); @@ -3103,10 +3033,7 @@ public static function provideDefaultValues() ]; } - /** - * @dataProvider provideBooleanDefaultValues - * @covers \Phinx\Db\Adapter\SqliteAdapter::parseDefaultValue - */ + #[DataProvider('provideBooleanDefaultValues')] public function testGetColumnsForBooleanDefaults($tableDef, $exp) { if (!$this->adapter->databaseVersionAtLeast('3.24')) { @@ -3134,10 +3061,7 @@ public static function provideBooleanDefaultValues() ]; } - /** - * @dataProvider provideTablesForTruncation - * @covers \Phinx\Db\Adapter\SqliteAdapter::truncateTable - */ + #[DataProvider('provideTablesForTruncation')] public function testTruncateTable($tableDef, $tableName, $tableId) { $conn = $this->adapter->getConnection(); diff --git a/tests/TestCase/Db/Adapter/SqlserverAdapterTest.php b/tests/TestCase/Db/Adapter/SqlserverAdapterTest.php index 8719d2d1..004a9f49 100644 --- a/tests/TestCase/Db/Adapter/SqlserverAdapterTest.php +++ b/tests/TestCase/Db/Adapter/SqlserverAdapterTest.php @@ -8,7 +8,6 @@ use Cake\Console\TestSuite\StubConsoleInput; use Cake\Console\TestSuite\StubConsoleOutput; use Cake\Database\Connection; -use Cake\Database\Query; use Cake\Datasource\ConnectionManager; use InvalidArgumentException; use Migrations\Db\Adapter\SqlserverAdapter; @@ -16,6 +15,8 @@ use Migrations\Db\Table; use Migrations\Db\Table\Column; use Migrations\Db\Table\ForeignKey; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -620,9 +621,7 @@ public static function columnsProvider() ]; } - /** - * @dataProvider columnsProvider - */ + #[DataProvider('columnsProvider')] public function testGetColumns($colName, $type, $options) { $table = new Table('t', [], $this->adapter); @@ -930,9 +929,9 @@ public static function nonExistentForeignKeyColumnsProvider(): array } /** - * @dataProvider nonExistentForeignKeyColumnsProvider * @param array $columns */ + #[DataProvider('nonExistentForeignKeyColumnsProvider')] public function testDropForeignKeyByNonExistentKeyColumns(array $columns) { $refTable = new Table('ref_table', [], $this->adapter); @@ -998,9 +997,7 @@ public function testDropForeignKeyByName() $this->assertFalse($this->adapter->hasForeignKey($table->getName(), ['ref_table_id'])); } - /** - * @dataProvider provideForeignKeysToCheck - */ + #[DataProvider('provideForeignKeysToCheck')] public function testHasForeignKey($tableDef, $key, $exp) { $conn = $this->adapter->getConnection(); @@ -1116,9 +1113,7 @@ public function testAddColumnComment() $this->assertEquals($comment, $resultComment, 'Dont set column comment correctly'); } - /** - * @dependss testAddColumnComment - */ + #[Depends('testAddColumnComment')] public function testChangeColumnComment() { $table = new Table('table1', [], $this->adapter); @@ -1133,9 +1128,7 @@ public function testChangeColumnComment() $this->assertEquals($comment, $resultComment, 'Dont change column comment correctly'); } - /** - * @depends testAddColumnComment - */ + #[Depends('testAddColumnComment')] public function testRemoveColumnComment() { $table = new Table('table1', [], $this->adapter); @@ -1300,7 +1293,7 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_INSERT); + $builder = $this->adapter->getInsertBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) ->into('table1') @@ -1310,7 +1303,7 @@ public function testQueryBuilder() $stm->closeCursor(); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_SELECT); + $builder = $this->adapter->getSelectBuilder(); $stm = $builder ->select('*') ->from('table1') @@ -1325,7 +1318,7 @@ public function testQueryBuilder() $stm->closeCursor(); - $builder = $this->adapter->getQueryBuilder(Query::TYPE_DELETE); + $builder = $this->adapter->getDeleteBuilder(); $stm = $builder ->delete('table1') ->where(['int_col <' => 2]) diff --git a/tests/TestCase/Db/Table/ColumnTest.php b/tests/TestCase/Db/Table/ColumnTest.php index 7c985984..c3a5bf69 100644 --- a/tests/TestCase/Db/Table/ColumnTest.php +++ b/tests/TestCase/Db/Table/ColumnTest.php @@ -5,6 +5,7 @@ use Cake\Core\Configure; use Migrations\Db\Table\Column; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -31,9 +32,7 @@ public function testSetOptionsIdentity() $this->assertTrue($column->isIdentity()); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testColumnNullFeatureFlag() { $column = new Column(); diff --git a/tests/TestCase/Db/Table/ForeignKeyTest.php b/tests/TestCase/Db/Table/ForeignKeyTest.php index 73828038..573a0b0b 100644 --- a/tests/TestCase/Db/Table/ForeignKeyTest.php +++ b/tests/TestCase/Db/Table/ForeignKeyTest.php @@ -5,6 +5,7 @@ use InvalidArgumentException; use Migrations\Db\Table\ForeignKey; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -37,8 +38,8 @@ public function testInitiallyActionsEmpty() /** * @param string $dirtyValue * @param string $valueOfConstant - * @dataProvider actionsProvider */ + #[DataProvider('actionsProvider')] public function testBothActionsCanBeSetThroughSetters($dirtyValue, $valueOfConstant) { $this->fk->setOnDelete($dirtyValue)->setOnUpdate($dirtyValue); @@ -49,8 +50,8 @@ public function testBothActionsCanBeSetThroughSetters($dirtyValue, $valueOfConst /** * @param string $dirtyValue * @param string $valueOfConstant - * @dataProvider actionsProvider */ + #[DataProvider('actionsProvider')] public function testBothActionsCanBeSetThroughOptions($dirtyValue, $valueOfConstant) { $this->fk->setOptions([ diff --git a/tests/TestCase/Db/Table/TableTest.php b/tests/TestCase/Db/Table/TableTest.php index 445bc8a0..679650c5 100644 --- a/tests/TestCase/Db/Table/TableTest.php +++ b/tests/TestCase/Db/Table/TableTest.php @@ -13,6 +13,7 @@ use Phinx\Db\Table; use Phinx\Db\Table\Column; use Phinx\Db\Table\Index; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionProperty; use RuntimeException; @@ -112,10 +113,10 @@ public function testAddIndexWithIndexObject() } /** - * @dataProvider provideTimestampColumnNames * @param AdapterInterface $adapter * @param string|null $createdAtColumnName * @param string|null $updatedAtColumnName * @param string $expectedCreatedAtColumnName * @param string $expectedUpdatedAtColumnName * @param bool $withTimezone */ + #[DataProvider('provideTimestampColumnNames')] public function testAddTimestamps(AdapterInterface $adapter, $createdAtColumnName, $updatedAtColumnName, $expectedCreatedAtColumnName, $expectedUpdatedAtColumnName, $withTimezone) { $table = new Table('ntable', [], $adapter); @@ -143,9 +144,9 @@ public function testAddTimestamps(AdapterInterface $adapter, $createdAtColumnNam } /** - * @dataProvider provideAdapters * @param AdapterInterface $adapter */ + #[DataProvider('provideAdapters')] public function testAddTimestampsNoUpdated(AdapterInterface $adapter) { $table = new Table('ntable', [], $adapter); @@ -168,9 +169,9 @@ public function testAddTimestampsNoUpdated(AdapterInterface $adapter) } /** - * @dataProvider provideAdapters * @param AdapterInterface $adapter */ + #[DataProvider('provideAdapters')] public function testAddTimestampsNoCreated(AdapterInterface $adapter) { $table = new Table('ntable', [], $adapter); @@ -194,9 +195,9 @@ public function testAddTimestampsNoCreated(AdapterInterface $adapter) } /** - * @dataProvider provideAdapters * @param AdapterInterface $adapter */ + #[DataProvider('provideAdapters')] public function testAddTimestampsThrowsOnBothFalse(AdapterInterface $adapter) { $table = new Table('ntable', [], $adapter); @@ -206,7 +207,6 @@ public function testAddTimestampsThrowsOnBothFalse(AdapterInterface $adapter) } /** - * @dataProvider provideTimestampColumnNames * @param AdapterInterface $adapter * @param string|null $createdAtColumnName * @param string|null $updatedAtColumnName @@ -214,6 +214,7 @@ public function testAddTimestampsThrowsOnBothFalse(AdapterInterface $adapter) * @param string $expectedUpdatedAtColumnName * @param bool $withTimezone */ + #[DataProvider('provideTimestampColumnNames')] public function testAddTimestampsWithTimezone(AdapterInterface $adapter, $createdAtColumnName, $updatedAtColumnName, $expectedCreatedAtColumnName, $expectedUpdatedAtColumnName, $withTimezone) { $table = new Table('ntable', [], $adapter); @@ -414,10 +415,10 @@ public function testGetColumn() } /** - * @dataProvider removeIndexDataprovider * @param string $indexIdentifier * @param Index $index */ + #[DataProvider('removeIndexDataprovider')] public function testRemoveIndex($indexIdentifier, Index $index) { $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') diff --git a/tests/TestCase/Migration/EnvironmentTest.php b/tests/TestCase/Migration/EnvironmentTest.php index 13e040d5..6d24b088 100644 --- a/tests/TestCase/Migration/EnvironmentTest.php +++ b/tests/TestCase/Migration/EnvironmentTest.php @@ -101,7 +101,7 @@ public function testCurrentVersion() ->getMock(); $stub->expects($this->any()) ->method('getVersions') - ->will($this->returnValue([20110301080000])); + ->willReturn([20110301080000]); $this->environment->setAdapter($stub); @@ -121,14 +121,16 @@ public function testExecutingAMigrationUp() $this->environment->setAdapter($adapterStub); // up - $upMigration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20110301080000']) - ->addMethods(['up']) - ->getMock(); - $upMigration->expects($this->once()) - ->method('up'); + $upMigration = new class ('mockenv', 20110301080000) extends AbstractMigration { + public bool $executed = false; + public function up(): void + { + $this->executed = true; + } + }; $this->environment->executeMigration($upMigration, MigrationInterface::UP); + $this->assertTrue($upMigration->executed); } public function testExecutingAMigrationDown() @@ -144,14 +146,16 @@ public function testExecutingAMigrationDown() $this->environment->setAdapter($adapterStub); // down - $downMigration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20110301080000']) - ->addMethods(['down']) - ->getMock(); - $downMigration->expects($this->once()) - ->method('down'); + $downMigration = new class ('mockenv', 20110301080000) extends AbstractMigration { + public bool $executed = false; + public function down(): void + { + $this->executed = true; + } + }; $this->environment->executeMigration($downMigration, MigrationInterface::DOWN); + $this->assertTrue($downMigration->executed); } public function testExecutingAMigrationWithTransactions() @@ -168,19 +172,21 @@ public function testExecutingAMigrationWithTransactions() $adapterStub->expects($this->exactly(2)) ->method('hasTransactions') - ->will($this->returnValue(true)); + ->willReturn(true); $this->environment->setAdapter($adapterStub); // migrate - $migration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20110301080000']) - ->addMethods(['up']) - ->getMock(); - $migration->expects($this->once()) - ->method('up'); + $migration = new class ('mockenv', 20110301080000) extends AbstractMigration { + public bool $executed = false; + public function up(): void + { + $this->executed = true; + } + }; $this->environment->executeMigration($migration, MigrationInterface::UP); + $this->assertTrue($migration->executed); } public function testExecutingAChangeMigrationUp() @@ -196,14 +202,16 @@ public function testExecutingAChangeMigrationUp() $this->environment->setAdapter($adapterStub); // migration - $migration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20130301080000']) - ->addMethods(['change']) - ->getMock(); - $migration->expects($this->once()) - ->method('change'); + $migration = new class ('mockenv', 20130301080000) extends AbstractMigration { + public bool $executed = false; + public function change(): void + { + $this->executed = true; + } + }; $this->environment->executeMigration($migration, MigrationInterface::UP); + $this->assertTrue($migration->executed); } public function testExecutingAChangeMigrationDown() @@ -219,14 +227,16 @@ public function testExecutingAChangeMigrationDown() $this->environment->setAdapter($adapterStub); // migration - $migration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20130301080000']) - ->addMethods(['change']) - ->getMock(); - $migration->expects($this->once()) - ->method('change'); + $migration = new class ('mockenv', 20130301080000) extends AbstractMigration { + public bool $executed = false; + public function change(): void + { + $this->executed = true; + } + }; $this->environment->executeMigration($migration, MigrationInterface::DOWN); + $this->assertTrue($migration->executed); } public function testExecutingAFakeMigration() @@ -242,14 +252,16 @@ public function testExecutingAFakeMigration() $this->environment->setAdapter($adapterStub); // migration - $migration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20130301080000']) - ->addMethods(['change']) - ->getMock(); - $migration->expects($this->never()) - ->method('change'); + $migration = new class ('mockenv', 20130301080000) extends AbstractMigration { + public bool $executed = false; + public function change(): void + { + $this->executed = true; + } + }; $this->environment->executeMigration($migration, MigrationInterface::UP, true); + $this->assertFalse($migration->executed); } public function testGettingInputObject() @@ -273,16 +285,24 @@ public function testExecuteMigrationCallsInit() $this->environment->setAdapter($adapterStub); // up - $upMigration = $this->getMockBuilder(AbstractMigration::class) - ->setConstructorArgs(['mockenv', '20110301080000']) - ->addMethods(['up', 'init']) - ->getMock(); - $upMigration->expects($this->once()) - ->method('up'); - $upMigration->expects($this->once()) - ->method('init'); + $upMigration = new class ('mockenv', 20110301080000) extends AbstractMigration { + public bool $initExecuted = false; + public bool $upExecuted = false; + + public function init(): void + { + $this->initExecuted = true; + } + + public function up(): void + { + $this->upExecuted = true; + } + }; $this->environment->executeMigration($upMigration, MigrationInterface::UP); + $this->assertTrue($upMigration->initExecuted); + $this->assertTrue($upMigration->upExecuted); } public function testExecuteSeedInit() @@ -295,16 +315,23 @@ public function testExecuteSeedInit() $this->environment->setAdapter($adapterStub); // up - $seed = $this->getMockBuilder(AbstractSeed::class) - ->addMethods(['init']) - ->onlyMethods(['run']) - ->getMock(); + $seed = new class ('mockenv', 20110301080000) extends AbstractSeed { + public bool $initExecuted = false; + public bool $runExecuted = false; + + public function init(): void + { + $this->initExecuted = true; + } - $seed->expects($this->once()) - ->method('run'); - $seed->expects($this->once()) - ->method('init'); + public function run(): void + { + $this->runExecuted = true; + } + }; $this->environment->executeSeed($seed); + $this->assertTrue($seed->initExecuted); + $this->assertTrue($seed->runExecuted); } } diff --git a/tests/TestCase/Migration/ManagerTest.php b/tests/TestCase/Migration/ManagerTest.php index f05a6dbb..764b9a5b 100644 --- a/tests/TestCase/Migration/ManagerTest.php +++ b/tests/TestCase/Migration/ManagerTest.php @@ -15,6 +15,7 @@ use Migrations\Migration\Manager; use Migrations\Shim\OutputAdapter; use Phinx\Console\Command\AbstractCommand; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RuntimeException; use Symfony\Component\Console\Input\InputInterface; @@ -174,7 +175,7 @@ public function testPrintStatusMethod(): void ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120111235330' => [ @@ -193,7 +194,7 @@ public function testPrintStatusMethod(): void 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); $return = $this->manager->printStatus(); @@ -220,7 +221,7 @@ public function testPrintStatusMethodJsonFormat(): void ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120111235330' => [ @@ -239,7 +240,7 @@ public function testPrintStatusMethodJsonFormat(): void 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); $return = $this->manager->printStatus(AbstractCommand::FORMAT_JSON); $expected = [ @@ -265,7 +266,7 @@ public function testPrintStatusMethodWithBreakpointSet(): void ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120111235330' => [ @@ -284,7 +285,7 @@ public function testPrintStatusMethodWithBreakpointSet(): void 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); $return = $this->manager->printStatus(); @@ -330,7 +331,7 @@ public function testPrintStatusMethodWithMissingMigrations() ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120103083300' => [ @@ -349,7 +350,7 @@ public function testPrintStatusMethodWithMissingMigrations() 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); @@ -389,7 +390,7 @@ public function testPrintStatusMethodWithMissingLastMigration() ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120111235330' => [ @@ -416,7 +417,7 @@ public function testPrintStatusMethodWithMissingLastMigration() 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); @@ -450,7 +451,7 @@ public function testPrintStatusMethodWithMissingMigrationsAndBreakpointSet() ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120103083300' => [ @@ -469,7 +470,7 @@ public function testPrintStatusMethodWithMissingMigrationsAndBreakpointSet() 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); $return = $this->manager->printStatus(); @@ -509,14 +510,15 @@ public function testPrintStatusMethodWithDownMigrations() ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue([ + ->willReturn([ '20120111235330' => [ 'version' => '20120111235330', 'start_time' => '2012-01-16 18:35:40', 'end_time' => '2012-01-16 18:35:41', 'migration_name' => '', 'breakpoint' => 0, - ]])); + ], + ]); $this->manager->setEnvironment($envStub); @@ -544,7 +546,7 @@ public function testPrintStatusMethodWithMissingAndDownMigrations() ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue([ + ->willReturn([ '20120111235330' => [ 'version' => '20120111235330', @@ -568,7 +570,8 @@ public function testPrintStatusMethodWithMissingAndDownMigrations() 'end_time' => '2012-01-16 18:35:41', 'migration_name' => 'Example', 'breakpoint' => 0, - ]])); + ], + ]); $this->manager->setEnvironment($envStub); @@ -646,12 +649,12 @@ public function testGettingAValidEnvironment() * Test that migrating by date chooses the correct * migration to point to. * - * @dataProvider migrateDateDataProvider * @param string[] $availableMigrations * @param string $dateString * @param string $expectedMigration * @param string $message */ + #[DataProvider('migrateDateDataProvider')] public function testMigrationsByDate(array $availableMigrations, $dateString, $expectedMigration, $message) { // stub environment @@ -664,7 +667,7 @@ public function testMigrationsByDate(array $availableMigrations, $dateString, $e } else { $envStub->expects($this->once()) ->method('getVersions') - ->will($this->returnValue($availableMigrations)); + ->willReturn($availableMigrations); } $this->manager->setEnvironment($envStub); $this->manager->migrateToDateTime(new DateTime($dateString)); @@ -680,9 +683,8 @@ public function testMigrationsByDate(array $availableMigrations, $dateString, $e /** * Test that rollbacking to version chooses the correct * migration to point to. - * - * @dataProvider rollbackToVersionDataProvider */ + #[DataProvider('rollbackToVersionDataProvider')] public function testRollbackToVersion($availableRollbacks, $version, $expectedOutput) { // stub environment @@ -691,7 +693,7 @@ public function testRollbackToVersion($availableRollbacks, $version, $expectedOu ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue($availableRollbacks)); + ->willReturn($availableRollbacks); $this->manager->setEnvironment($envStub); $this->manager->rollback($version); @@ -713,9 +715,8 @@ public function testRollbackToVersion($availableRollbacks, $version, $expectedOu /** * Test that rollbacking to date chooses the correct * migration to point to. - * - * @dataProvider rollbackToDateDataProvider */ + #[DataProvider('rollbackToDateDataProvider')] public function testRollbackToDate($availableRollbacks, $version, $expectedOutput) { // stub environment @@ -724,7 +725,7 @@ public function testRollbackToDate($availableRollbacks, $version, $expectedOutpu ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue($availableRollbacks)); + ->willReturn($availableRollbacks); $this->manager->setEnvironment($envStub); $this->manager->rollback($version, false, false); @@ -746,9 +747,8 @@ public function testRollbackToDate($availableRollbacks, $version, $expectedOutpu /** * Test that rollbacking to version by execution time chooses the correct * migration to point to. - * - * @dataProvider rollbackToVersionByExecutionTimeDataProvider */ + #[DataProvider('rollbackToVersionByExecutionTimeDataProvider')] public function testRollbackToVersionByExecutionTime($availableRollbacks, $version, $expectedOutput) { // stub environment @@ -757,7 +757,7 @@ public function testRollbackToVersionByExecutionTime($availableRollbacks, $versi ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue($availableRollbacks)); + ->willReturn($availableRollbacks); // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); @@ -785,9 +785,8 @@ public function testRollbackToVersionByExecutionTime($availableRollbacks, $versi /** * Test that rollbacking to version by migration name chooses the correct * migration to point to. - * - * @dataProvider rollbackToVersionByExecutionTimeDataProvider */ + #[DataProvider('rollbackToVersionByExecutionTimeDataProvider')] public function testRollbackToVersionByName($availableRollbacks, $version, $expectedOutput) { // stub environment @@ -796,7 +795,7 @@ public function testRollbackToVersionByName($availableRollbacks, $version, $expe ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue($availableRollbacks)); + ->willReturn($availableRollbacks); // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); @@ -824,9 +823,8 @@ public function testRollbackToVersionByName($availableRollbacks, $version, $expe /** * Test that rollbacking to date by execution time chooses the correct * migration to point to. - * - * @dataProvider rollbackToDateByExecutionTimeDataProvider */ + #[DataProvider('rollbackToDateByExecutionTimeDataProvider')] public function testRollbackToDateByExecutionTime($availableRollbacks, $date, $expectedOutput) { // stub environment @@ -835,7 +833,7 @@ public function testRollbackToDateByExecutionTime($availableRollbacks, $date, $e ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue($availableRollbacks)); + ->willReturn($availableRollbacks); // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); @@ -869,12 +867,12 @@ public function testRollbackToVersionWithSingleMigrationDoesNotFail(): void ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue([ + ->willReturn([ '20120111235330' => ['version' => '20120111235330', 'migration' => '', 'breakpoint' => 0], - ])); + ]); $envStub->expects($this->any()) ->method('getVersions') - ->will($this->returnValue([20120111235330])); + ->willReturn([20120111235330]); $this->manager->setEnvironment($envStub); $this->manager->rollback(); @@ -894,23 +892,19 @@ public function testRollbackToVersionWithTwoMigrations(): void ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will( - $this->returnValue( - [ - '20120111235330' => ['version' => '20120111235330', 'migration' => '', 'breakpoint' => 0], - '20120116183504' => ['version' => '20120815145812', 'migration' => '', 'breakpoint' => 0], - ] - ) + ->willReturn( + [ + '20120111235330' => ['version' => '20120111235330', 'migration' => '', 'breakpoint' => 0], + '20120116183504' => ['version' => '20120815145812', 'migration' => '', 'breakpoint' => 0], + ] ); $envStub->expects($this->any()) ->method('getVersions') - ->will( - $this->returnValue( - [ - 20120111235330, - 20120116183504, - ] - ) + ->willReturn( + [ + 20120111235330, + 20120116183504, + ] ); $this->manager->setEnvironment($envStub); @@ -922,9 +916,8 @@ public function testRollbackToVersionWithTwoMigrations(): void /** * Test that rollbacking last migration - * - * @dataProvider rollbackLastDataProvider */ + #[DataProvider('rollbackLastDataProvider')] public function testRollbackLast(array $availableRolbacks, string $versionOrder, string $expectedOutput): void { // stub environment @@ -933,7 +926,7 @@ public function testRollbackLast(array $availableRolbacks, string $versionOrder, ->getMock(); $envStub->expects($this->any()) ->method('getVersionLog') - ->will($this->returnValue($availableRolbacks)); + ->willReturn($availableRolbacks); // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); @@ -2675,7 +2668,7 @@ public function testInvalidVersionBreakpoint(): void ->getMock(); $envStub->expects($this->once()) ->method('getVersionLog') - ->will($this->returnValue( + ->willReturn( [ '20120111235330' => [ @@ -2686,7 +2679,7 @@ public function testInvalidVersionBreakpoint(): void 'breakpoint' => '0', ], ] - )); + ); $this->manager->setEnvironment($envStub); $this->manager->setBreakpoint(20120133235330); diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index b2098c74..0d3a8875 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -22,6 +22,7 @@ use InvalidArgumentException; use Migrations\Migrations; use Phinx\Db\Adapter\WrapperInterface; +use PHPUnit\Framework\Attributes\DataProvider; use function Cake\Core\env; /** @@ -130,9 +131,9 @@ public static function backendProvider(): array /** * Tests the status method * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testStatus(string $backend) { Configure::write('Migrations.backend', $backend); @@ -166,9 +167,9 @@ public function testStatus(string $backend) /** * Tests the migrations and rollbacks * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMigrateAndRollback($backend) { Configure::write('Migrations.backend', $backend); @@ -255,9 +256,9 @@ public function testMigrateAndRollback($backend) /** * Tests the collation table behavior when using MySQL * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testCreateWithEncoding($backend) { Configure::write('Migrations.backend', $backend); @@ -284,9 +285,9 @@ public function testCreateWithEncoding($backend) * Tests calling Migrations::markMigrated without params marks everything * as migrated * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedAll($backend) { Configure::write('Migrations.backend', $backend); @@ -324,9 +325,9 @@ public function testMarkMigratedAll($backend) * string 'all' marks everything * as migrated * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedAllAsVersion($backend) { Configure::write('Migrations.backend', $backend); @@ -363,9 +364,9 @@ public function testMarkMigratedAllAsVersion($backend) * Tests calling Migrations::markMigrated with the target option will mark * only up to that one * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedTarget($backend) { Configure::write('Migrations.backend', $backend); @@ -408,9 +409,9 @@ public function testMarkMigratedTarget($backend) * Tests calling Migrations::markMigrated with the target option set to a * non-existent target will throw an exception * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedTargetError($backend) { Configure::write('Migrations.backend', $backend); @@ -424,9 +425,9 @@ public function testMarkMigratedTargetError($backend) * Tests calling Migrations::markMigrated with the target option with the exclude * option will mark only up to that one, excluding it * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedTargetExclude($backend) { Configure::write('Migrations.backend', $backend); @@ -469,9 +470,9 @@ public function testMarkMigratedTargetExclude($backend) * Tests calling Migrations::markMigrated with the target option with the only * option will mark only that specific migrations * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedTargetOnly($backend) { Configure::write('Migrations.backend', $backend); @@ -514,9 +515,9 @@ public function testMarkMigratedTargetOnly($backend) * Tests calling Migrations::markMigrated with the target option, the only option * and the exclude option will throw an exception * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedTargetExcludeOnly($backend) { Configure::write('Migrations.backend', $backend); @@ -530,9 +531,9 @@ public function testMarkMigratedTargetExcludeOnly($backend) * Tests calling Migrations::markMigrated with the target option with the exclude * option will mark only up to that one, excluding it * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMarkMigratedVersion($backend) { Configure::write('Migrations.backend', $backend); @@ -575,9 +576,9 @@ public function testMarkMigratedVersion($backend) * Tests that calling the migrations methods while passing * parameters will override the default ones * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testOverrideOptions($backend) { Configure::write('Migrations.backend', $backend); @@ -646,9 +647,9 @@ public function testOverrideOptions($backend) * Tests that calling the migrations methods while passing the ``date`` * parameter works as expected * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testMigrateDateOption($backend) { Configure::write('Migrations.backend', $backend); @@ -825,9 +826,9 @@ public function testMigrateDateOption($backend) /** * Tests seeding the database * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testSeed($backend) { Configure::write('Migrations.backend', $backend); @@ -904,9 +905,9 @@ public function testSeed($backend) /** * Tests seeding the database with seeder * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testSeedOneSeeder($backend) { Configure::write('Migrations.backend', $backend); @@ -956,9 +957,9 @@ public function testSeedOneSeeder($backend) /** * Tests seeding the database with seeder * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testSeedCallSeeder($backend) { Configure::write('Migrations.backend', $backend); @@ -1020,9 +1021,9 @@ public function testSeedCallSeeder($backend) /** * Tests that requesting a unexistant seed throws an exception * - * @dataProvider backendProvider * @return void */ + #[DataProvider('backendProvider')] public function testSeedWrongSeed($backend) { Configure::write('Migrations.backend', $backend); @@ -1035,12 +1036,12 @@ public function testSeedWrongSeed($backend) /** * Tests migrating the baked snapshots with builtin backend * - * @dataProvider snapshotMigrationsProvider * @param string $basePath Snapshot file path * @param string $filename Snapshot file name * @param array $flags Feature flags * @return void */ + #[DataProvider('snapshotMigrationsProvider')] public function testMigrateSnapshotsBuiltin(string $basePath, string $filename, array $flags = []): void { Configure::write('Migrations.backend', 'builtin'); @@ -1050,12 +1051,12 @@ public function testMigrateSnapshotsBuiltin(string $basePath, string $filename, /** * Tests migrating the baked snapshots * - * @dataProvider snapshotMigrationsProvider * @param string $basePath Snapshot file path * @param string $filename Snapshot file name * @param array $flags Feature flags * @return void */ + #[DataProvider('snapshotMigrationsProvider')] public function testMigrateSnapshotsPhinx(string $basePath, string $filename, array $flags = []): void { $this->runMigrateSnapshots($basePath, $filename, $flags); @@ -1108,9 +1109,8 @@ protected function runMigrateSnapshots(string $basePath, string $filename, array /** * Tests that migrating in case of error throws an exception - * - * @dataProvider backendProvider */ + #[DataProvider('backendProvider')] public function testMigrateErrors($backend) { Configure::write('Migrations.backend', $backend); @@ -1122,9 +1122,8 @@ public function testMigrateErrors($backend) /** * Tests that rolling back in case of error throws an exception - * - * @dataProvider backendProvider */ + #[DataProvider('backendProvider')] public function testRollbackErrors($backend) { Configure::write('Migrations.backend', $backend); @@ -1137,9 +1136,8 @@ public function testRollbackErrors($backend) /** * Tests that marking migrated a non-existant migrations returns an error * and can return a error message - * - * @dataProvider backendProvider */ + #[DataProvider('backendProvider')] public function testMarkMigratedErrors($backend) { Configure::write('Migrations.backend', $backend); diff --git a/tests/TestCase/TestSuite/MigratorTest.php b/tests/TestCase/TestSuite/MigratorTest.php index 631f7723..4fa05b2d 100644 --- a/tests/TestCase/TestSuite/MigratorTest.php +++ b/tests/TestCase/TestSuite/MigratorTest.php @@ -19,6 +19,7 @@ use Cake\TestSuite\ConnectionHelper; use Cake\TestSuite\TestCase; use Migrations\TestSuite\Migrator; +use PHPUnit\Framework\Attributes\Depends; use RuntimeException; class MigratorTest extends TestCase @@ -139,9 +140,7 @@ public function testRunManyMultipleSkip(): void } } - /** - * @depends testMigrateDropNoTruncate - */ + #[Depends('testMigrateDropNoTruncate')] public function testTruncateAfterMigrations(): void { $this->testMigrateDropNoTruncate(); diff --git a/tests/TestCase/Util/ColumnParserTest.php b/tests/TestCase/Util/ColumnParserTest.php index 059d9b83..f9600197 100644 --- a/tests/TestCase/Util/ColumnParserTest.php +++ b/tests/TestCase/Util/ColumnParserTest.php @@ -18,8 +18,6 @@ /** * Tests the ColumnParser - * - * @covers \Migrations\Util\ColumnParser */ class ColumnParserTest extends TestCase { @@ -39,9 +37,6 @@ public function setUp(): void $this->columnParser = new ColumnParser(); } - /** - * @covers \Migrations\Util\ColumnParser::parseFields() - */ public function testParseFields() { $this->assertEquals([ @@ -232,9 +227,6 @@ public function testParseFields() $this->assertEquals($expected, $actual); } - /** - * @covers \Migrations\Util\ColumnParser::parseIndexes() - */ public function testParseIndexes() { $this->assertEquals(['UNIQUE_ID' => [ @@ -255,9 +247,6 @@ public function testParseIndexes() ])); } - /** - * @covers \Migrations\Util\ColumnParser::parsePrimaryKey() - */ public function testParsePrimaryKey() { $this->assertEquals(['id'], $this->columnParser->parsePrimaryKey(['id:primary'])); @@ -269,9 +258,6 @@ public function testParsePrimaryKey() ); } - /** - * @covers \Migrations\Util\ColumnParser::validArguments() - */ public function testValidArguments() { $this->assertEquals( @@ -324,9 +310,6 @@ public function testValidArguments() ); } - /** - * @covers \Migrations\Util\ColumnParser::getType() - */ public function testGetType() { $this->assertSame('integer', $this->columnParser->getType('id', null)); @@ -349,9 +332,6 @@ public function testGetType() $this->assertSame('decimal', $this->columnParser->getType('longitude', null)); } - /** - * @covers \Migrations\Util\ColumnParser::getTypeAndLength() - */ public function testGetTypeAndLength() { $this->assertEquals(['string', 255], $this->columnParser->getTypeAndLength('name', 'string')); @@ -366,9 +346,6 @@ public function testGetTypeAndLength() $this->assertEquals(['decimal', [10, 6]], $this->columnParser->getTypeAndLength('latitude', 'decimal[10,6]')); } - /** - * @covers \Migrations\Util\ColumnParser::getLength() - */ public function testGetLength() { $this->assertSame(255, $this->columnParser->getLength('string')); @@ -378,9 +355,6 @@ public function testGetLength() $this->assertNull($this->columnParser->getLength('text')); } - /** - * @covers \Migrations\Util\ColumnParser::getIndexName() - */ public function testGetIndexName() { $this->assertSame('SOME_INDEX', $this->columnParser->getIndexName('id', null, 'SOME_INDEX', true)); diff --git a/tests/TestCase/View/Helper/MigrationHelperTest.php b/tests/TestCase/View/Helper/MigrationHelperTest.php index 394e548d..79aa3554 100644 --- a/tests/TestCase/View/Helper/MigrationHelperTest.php +++ b/tests/TestCase/View/Helper/MigrationHelperTest.php @@ -134,9 +134,6 @@ public function tearDown(): void unset($this->helper, $this->view, $this->collection, $this->connection); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::tableMethod() - */ public function testTableMethod() { $this->assertSame('drop', $this->helper->tableMethod('drop_table')); @@ -144,9 +141,6 @@ public function testTableMethod() $this->assertSame('update', $this->helper->tableMethod('other_method')); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::indexMethod() - */ public function testIndexMethod() { $this->assertSame('removeIndex', $this->helper->indexMethod('drop_field')); @@ -154,9 +148,6 @@ public function testIndexMethod() $this->assertSame('addIndex', $this->helper->indexMethod('alter_field')); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::columnMethod() - */ public function testColumnMethod() { $this->assertSame('removeColumn', $this->helper->columnMethod('drop_field')); @@ -164,9 +155,6 @@ public function testColumnMethod() $this->assertSame('changeColumn', $this->helper->columnMethod('alter_field')); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::columns() - */ public function testColumns() { $extra = []; @@ -217,9 +205,6 @@ public function testColumns() ], $this->helper->columns('users')); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::column() - */ public function testColumn() { $tableSchema = $this->collection->describe('users'); @@ -291,9 +276,6 @@ public function testColumn() ], $this->helper->column($tableSchema, 'updated')); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::value() - */ public function testValue() { $this->assertSame('null', $this->helper->value(null)); @@ -314,9 +296,6 @@ public function testValue() $this->assertSame("'o\\\"ne'", $this->helper->value('o"ne')); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::attributes() - */ public function testAttributes() { $attributes = [ @@ -389,9 +368,6 @@ public function testAttributes() $this->assertEquals($attributes, $result); } - /** - * @covers \Migrations\View\Helper\MigrationHelper::stringifyList() - */ public function testStringifyList() { $this->assertSame('', $this->helper->stringifyList([]));