Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.next: add PHPUnit 11 support #736

Merged
merged 8 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
17 changes: 17 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
</file>
<file src="src/Migration/Manager.php">
<ArgumentTypeCoercion>
<code><![CDATA[array_map(
function ($phpFile) {
return " <info>{$phpFile}</info>";
},
$phpFiles
)]]></code>
<code>array_merge($versions, array_keys($migrations))</code>
</ArgumentTypeCoercion>
<RedundantPropertyInitializationCheck>
Expand All @@ -137,13 +143,24 @@
</DeprecatedTrait>
</file>
<file src="src/Shim/OutputAdapter.php">
<ArgumentTypeCoercion>
<code>$messages</code>
<code>$messages</code>
</ArgumentTypeCoercion>
<LessSpecificReturnStatement>
<code><![CDATA[$this->io->level()]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code>self::VERBOSITY_*</code>
</MoreSpecificReturnType>
</file>
<file src="src/TestSuite/Migrator.php">
<ArgumentTypeCoercion>
<code>$dropTables</code>
<code>$phinxTables</code>
<code>$tables</code>
</ArgumentTypeCoercion>
</file>
<file src="src/Util/ColumnParser.php">
<ArgumentTypeCoercion>
<code><![CDATA[$this->regexpParseColumn]]></code>
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/BakeMigrationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\TestSuite\StringCompareTrait;
use Migrations\Command\BakeMigrationCommand;
use Migrations\Test\TestCase\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* BakeMigrationCommandTest class
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -181,7 +182,6 @@ public function testAddPrimaryKeyToExistingUsersTable()
}

/**
* @covers \Migrations\Command\BakeMigrationCommand::detectAction()
* @return void
*/
public function testDetectAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/MigrationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/Phinx/MarkMigratedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/Phinx/SeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase/Config/AbstractConfigTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Class AbstractConfigTest
*
* @coversNothing
*/
abstract class AbstractConfigTestCase extends TestCase
{
Expand Down
56 changes: 4 additions & 52 deletions tests/TestCase/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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([]);
Expand All @@ -49,9 +38,6 @@ public function testArrayAccessMethods()
$this->assertArrayNotHasKey('foo', $config);
}

/**
* @covers \Phinx\Config\Config::offsetGet
*/
public function testUndefinedArrayAccess()
{
$config = new Config([]);
Expand All @@ -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([]);
Expand All @@ -118,9 +88,6 @@ public function testGetSeedPath()
$this->assertEquals('db/seeds1', $config->getSeedPath());
}

/**
* @covers \Phinx\Config\Config::getSeedPaths
*/
public function testGetSeedPathThrowsException()
{
$config = new Config([]);
Expand All @@ -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()
{
Expand All @@ -146,29 +111,21 @@ public function testGetMigrationBaseClassNameNoNamespace()
/**
* Checks if base class is returned correctly when specified without
* a namespace.
*
* @covers \Phinx\Config\Config::getMigrationBaseClassName
*/
public function testGetMigrationBaseClassNameNoNamespaceNoDrop()
{
$config = new Config(['migration_base_class' => 'BaseMigration']);
$this->assertEquals('BaseMigration', $config->getMigrationBaseClassName(false));
}

/**
* @covers \Phinx\Config\Config::getVersionOrder
*/
public function testGetVersionOrder()
{
$config = new Config([]);
$config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME;
$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
Expand All @@ -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 [
Expand Down Expand Up @@ -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]]);
Expand Down
10 changes: 4 additions & 6 deletions tests/TestCase/ConfigurationTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 7 additions & 4 deletions tests/TestCase/Db/Adapter/AdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Loading
Loading