Make test data providers static and declare array return types in db tests. (#20631)

This commit is contained in:
Wilmer Arambula
2025-10-21 08:28:49 -03:00
committed by GitHub
parent 9676e529eb
commit f983c66cf5
22 changed files with 73 additions and 61 deletions

View File

@@ -813,12 +813,12 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$this->assertEquals($eagerItemsCount, $lazyItemsCount);
}
public function aliasMethodProvider()
public static function aliasMethodProvider(): array
{
return [
['explicit'], // c
// ['querysyntax'], // {{@customer}}
// ['applyAlias'], // $query->applyAlias('customer', 'id') // _aliases are currently not being populated
// ['querysyntax'], // {{@customer}}
// ['applyAlias'], // $query->applyAlias('customer', 'id') // _aliases are currently not being populated
// later getRelationAlias() could be added
];
}
@@ -1129,7 +1129,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$this->assertInstanceOf('yiiunit\data\ar\Customer', $customerWithJoinIndexOrdered['user1']);
}
public function tableNameProvider()
public static function tableNameProvider(): array
{
return [
['order', 'order_item'],
@@ -1895,7 +1895,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$this->assertEquals($expectedAliases, $aliases);
}
public function filterTableNamesFromAliasesProvider()
public static function filterTableNamesFromAliasesProvider(): array
{
return [
'table name as string' => ['customer', []],
@@ -1907,7 +1907,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
];
}
public function legalValuesForFindByCondition()
public static function legalValuesForFindByCondition(): array
{
return [
[Customer::class, ['id' => 1]],
@@ -1938,7 +1938,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$this->assertTrue(true);
}
public function illegalValuesForFindByCondition()
public static function illegalValuesForFindByCondition(): array
{
return [
[Customer::class, [['`id`=`id` and 1' => 1]]],
@@ -2133,7 +2133,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
}
}
public function providerForUnlinkDelete()
public static function providerForUnlinkDelete(): array
{
return [
'with delete' => [true, 0],
@@ -2180,7 +2180,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$this->assertNotNull($order->virtualCustomer);
}
public function labelTestModelProvider()
public static function labelTestModelProvider(): array
{
$data = [];

View File

@@ -27,7 +27,7 @@ abstract class ColumnSchemaBuilderTest extends DatabaseTestCase
/**
* @return array
*/
public function typesProvider()
public static function typesProvider(): array
{
return [
['integer NULL DEFAULT NULL', Schema::TYPE_INTEGER, null, [

View File

@@ -245,7 +245,7 @@ SQL;
$this->assertEquals('user5@example.com', $command->queryScalar());
}
public function paramsNonWhereProvider()
public static function paramsNonWhereProvider(): array
{
return [
['SELECT SUBSTR(name, :len) FROM {{customer}} WHERE [[email]] = :email GROUP BY SUBSTR(name, :len)'],
@@ -380,7 +380,7 @@ SQL;
setlocale(LC_NUMERIC, $locale);
}
public function batchInsertSqlProvider()
public static function batchInsertSqlProvider(): array
{
return [
'issue11242' => [
@@ -615,7 +615,7 @@ SQL;
* Data provider for testInsertSelectFailed.
* @return array
*/
public function invalidSelectColumns()
public static function invalidSelectColumns(): array
{
return [
[[]],
@@ -805,7 +805,7 @@ SQL;
$this->assertNotNull($db->getSchema()->getTableSchema($toTableName, true));
}
public function upsertProvider()
public static function upsertProvider(): array
{
return [
'regular values' => [
@@ -1343,7 +1343,7 @@ SQL;
* Data provider for [[testGetRawSql()]].
* @return array test data
*/
public function dataProviderGetRawSql()
public static function dataProviderGetRawSql(): array
{
return [
[

View File

@@ -28,7 +28,7 @@ abstract class SchemaTest extends DatabaseTestCase
*/
protected $expectedSchemas;
public function pdoAttributesProvider()
public static function pdoAttributesProvider(): array
{
return [
[[PDO::ATTR_EMULATE_PREPARES => true]],
@@ -157,7 +157,7 @@ abstract class SchemaTest extends DatabaseTestCase
$this->assertNotSame($noCacheTable, $refreshedTable);
}
public function tableSchemaCachePrefixesProvider()
public static function tableSchemaCachePrefixesProvider(): array
{
$configs = [
[
@@ -558,7 +558,7 @@ abstract class SchemaTest extends DatabaseTestCase
$this->assertSame($expected, $columnSchema->dbTypecast($value));
}
public function columnSchemaDbTypecastBooleanPhpTypeProvider()
public static function columnSchemaDbTypecastBooleanPhpTypeProvider(): array
{
return [
[1, true],
@@ -646,7 +646,7 @@ abstract class SchemaTest extends DatabaseTestCase
}
}
public function constraintsProvider()
public static function constraintsProvider(): array
{
return [
'1: primary key' => ['T_constraints_1', 'primaryKey', new Constraint([
@@ -753,14 +753,14 @@ abstract class SchemaTest extends DatabaseTestCase
];
}
public function lowercaseConstraintsProvider()
public static function lowercaseConstraintsProvider(): array
{
return $this->constraintsProvider();
return static::constraintsProvider();
}
public function uppercaseConstraintsProvider()
public static function uppercaseConstraintsProvider(): array
{
return $this->constraintsProvider();
return static::constraintsProvider();
}
/**

View File

@@ -33,7 +33,7 @@ class ColumnSchemaBuilderTest extends \yiiunit\framework\db\ColumnSchemaBuilderT
/**
* @return array
*/
public function typesProvider()
public static function typesProvider(): array
{
return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [

View File

@@ -85,7 +85,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql);
}
public function batchInsertSqlProvider()
public static function batchInsertSqlProvider(): array
{
$data = parent::batchInsertSqlProvider();
$data['issue11242']['expected'] = 'INSERT INTO "type" ("int_col", "float_col", "char_col") VALUES (NULL, NULL, \'Kyiv {{city}}, Ukraine\')';

View File

@@ -87,11 +87,11 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
return $columns;
}
public function constraintsProvider()
public static function constraintsProvider(): array
{
$result = parent::constraintsProvider();
foreach ($result as $name => $constraints) {
$result[$name][2] = $this->convertPropertiesToAnycase($constraints[2]);
$result[$name][2] = static::convertPropertiesToAnycase($constraints[2]);
}
$result['1: check'][2] = false;
unset($result['1: index'][2][0]);
@@ -108,27 +108,17 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
return $result;
}
public function lowercaseConstraintsProvider(): void
{
$this->markTestSkipped('This test hangs on CUBRID.');
}
public function uppercaseConstraintsProvider(): void
{
$this->markTestSkipped('This test hangs on CUBRID.');
}
/**
* @param array|object|string $object
* @param bool $isProperty
* @return array|object|string
*/
private function convertPropertiesToAnycase($object, $isProperty = false)
private static function convertPropertiesToAnycase($object, $isProperty = false)
{
if (!$isProperty && \is_array($object)) {
$result = [];
foreach ($object as $name => $value) {
$result[] = $this->convertPropertiesToAnycase($value);
$result[] = static::convertPropertiesToAnycase($value);
}
return $result;
@@ -136,7 +126,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
if (\is_object($object)) {
foreach (array_keys((array) $object) as $name) {
$object->$name = $this->convertPropertiesToAnycase($object->$name, true);
$object->$name = static::convertPropertiesToAnycase($object->$name, true);
}
} elseif (\is_array($object) || \is_string($object)) {
$object = new AnyCaseValue($object);
@@ -144,4 +134,26 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
return $object;
}
/**
* @dataProvider lowercaseConstraintsProvider
* @param string $tableName
* @param string $type
* @param mixed $expected
*/
public function testTableSchemaConstraintsWithPdoLowercase($tableName, $type, $expected): void
{
$this->markTestSkipped('This test hangs on CUBRID.');
}
/**
* @dataProvider uppercaseConstraintsProvider
* @param string $tableName
* @param string $type
* @param mixed $expected
*/
public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $expected): void
{
$this->markTestSkipped('This test hangs on CUBRID.');
}
}

View File

@@ -90,7 +90,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
$this->assertEquals('user5@example.com', $command->queryScalar());
}
public function paramsNonWhereProvider()
public static function paramsNonWhereProvider(): array
{
return[
['SELECT SUBSTRING(name, :len, 6) AS name FROM {{customer}} WHERE [[email]] = :email GROUP BY name'],
@@ -122,7 +122,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
$this->assertEmpty($schema->getTableDefaultValues($tableName, true));
}
public function batchInsertSqlProvider()
public static function batchInsertSqlProvider(): array
{
$data = parent::batchInsertSqlProvider();
$data['issue11242']['expected'] = 'INSERT INTO [type] ([int_col], [float_col], [char_col]) VALUES (NULL, NULL, \'Kyiv {{city}}, Ukraine\')';

View File

@@ -25,7 +25,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
'dbo',
];
public function constraintsProvider()
public static function constraintsProvider(): array
{
$result = parent::constraintsProvider();
$result['1: check'][2][0]->expression = '([C_check]<>\'\')';
@@ -100,7 +100,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$this->assertEquals($expectedName, $quotedName);
}
public function quoteTableNameDataProvider()
public static function quoteTableNameDataProvider(): array
{
return [
['test', '[test]'],
@@ -127,7 +127,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$this->assertEquals($expectedName, $tableSchema->name);
}
public function getTableSchemaDataProvider()
public static function getTableSchemaDataProvider(): array
{
return [
['[dbo].[profile]', 'profile'],

View File

@@ -33,7 +33,7 @@ class ColumnSchemaBuilderTest extends \yiiunit\framework\db\ColumnSchemaBuilderT
/**
* @return array
*/
public function typesProvider()
public static function typesProvider(): array
{
return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [

View File

@@ -76,7 +76,7 @@ SQL;
$this->markTestSkipped('Schemas are not supported in MySQL.');
}
public function constraintsProvider()
public static function constraintsProvider(): array
{
$result = parent::constraintsProvider();

View File

@@ -33,7 +33,7 @@ class ColumnSchemaBuilderTest extends \yiiunit\framework\db\ColumnSchemaBuilderT
/**
* @return array
*/
public function typesProvider()
public static function typesProvider(): array
{
return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [

View File

@@ -42,7 +42,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
$this->assertSame('3', $db->getSchema()->getLastInsertID('profile_SEQ'));
}
public function batchInsertSqlProvider()
public static function batchInsertSqlProvider(): array
{
$data = parent::batchInsertSqlProvider();
$data['issue11242']['expected'] = 'INSERT ALL INTO "type" ("int_col", "float_col", "char_col") ' .
@@ -161,7 +161,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
}, 10);
}
public function paramsNonWhereProvider()
public static function paramsNonWhereProvider(): array
{
return [
['SELECT SUBSTR([[name]], :len) FROM {{customer}} WHERE [[email]] = :email GROUP BY SUBSTR([[name]], :len)'],

View File

@@ -110,7 +110,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$this->assertFalse($table->columns['id']->autoIncrement);
}
public function constraintsProvider()
public static function constraintsProvider(): array
{
$result = parent::constraintsProvider();
$result['1: check'][2][0]->expression = '"C_check" <> \'\'';

View File

@@ -215,7 +215,7 @@ class ActiveRecordTest extends \yiiunit\framework\db\ActiveRecordTest
$this->assertSame(1, $type->update(), 'The record got updated');
}
public function arrayValuesProvider()
public static function arrayValuesProvider(): array
{
return [
'simple arrays values' => [[

View File

@@ -19,7 +19,7 @@ class ArrayParserTest extends TestCase
$this->arrayParser = new ArrayParser();
}
public function convertProvider()
public static function convertProvider(): array
{
return [
['{}', []],

View File

@@ -80,7 +80,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
$this->assertSame('3', $db->getSchema()->getLastInsertID('schema1.profile_id_seq'));
}
public function dataProviderGetRawSql()
public static function dataProviderGetRawSql(): array
{
return array_merge(parent::dataProviderGetRawSql(), [
[
@@ -117,7 +117,7 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
$this->assertEquals(1, $command->execute());
}
public function batchInsertSqlProvider()
public static function batchInsertSqlProvider(): array
{
$data = parent::batchInsertSqlProvider();
$data['issue11242']['expected'] = 'INSERT INTO "type" ("int_col", "float_col", "char_col") VALUES (NULL, NULL, \'Kyiv {{city}}, Ukraine\')';

View File

@@ -261,7 +261,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$this->assertCount(3, $schema->getSchemaNames());
}
public function bigintValueProvider()
public static function bigintValueProvider(): array
{
return [
[8817806877],
@@ -402,7 +402,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$this->assertEquals(new Expression('timezone(\'UTC\'::text, \'1970-01-01 00:00:00+00\'::timestamp with time zone)'), $tableSchema->getColumn('timestamp')->defaultValue);
}
public function constraintsProvider()
public static function constraintsProvider(): array
{
$result = parent::constraintsProvider();
$result['1: check'][2][0]->expression = 'CHECK ((("C_check")::text <> \'\'::text))';

View File

@@ -33,7 +33,7 @@ class ColumnSchemaBuilderTest extends \yiiunit\framework\db\ColumnSchemaBuilderT
/**
* @return array
*/
public function typesProvider()
public static function typesProvider(): array
{
return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [

View File

@@ -105,7 +105,7 @@ SQL;
])->queryAll());
}
public function batchInsertSqlProvider()
public static function batchInsertSqlProvider(): array
{
$parent = parent::batchInsertSqlProvider();
unset($parent['wrongBehavior']); // Produces SQL syntax error: General error: 1 near ".": syntax error

View File

@@ -58,7 +58,7 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$this->assertEquals('item_id', $table->foreignKeys[0]['item_id']);
}
public function constraintsProvider()
public static function constraintsProvider(): array
{
$result = parent::constraintsProvider();
$result['1: primary key'][2]->name = null;

View File

@@ -18,7 +18,7 @@ use yiiunit\TestCase;
*/
class SqlTokenizerTest extends TestCase
{
public function sqlProvider()
public static function sqlProvider(): array
{
return [
'complex' => [