Make conditionProviders() method static and declare array return type array in QueryBuilderTest class. (#20633)

This commit is contained in:
Wilmer Arambula
2025-10-21 14:02:21 -03:00
committed by GitHub
parent f983c66cf5
commit 6067cbbd76
7 changed files with 449 additions and 173 deletions

View File

@@ -9,10 +9,12 @@
namespace yiiunit\framework\db\sqlite;
use PDO;
use yii\db\Expression;
use yii\db\Query;
use yii\db\Schema;
use yii\db\sqlite\QueryBuilder;
use yiiunit\data\base\TraversableObject;
use yiiunit\framework\support\DbHelper;
/**
* @group db
@@ -35,23 +37,67 @@ class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest
]);
}
public function conditionProvider()
public static function conditionProvider(): array
{
return array_merge(parent::conditionProvider(), [
'composite in using array objects' => [
['in', new TraversableObject(['id', 'name']), new TraversableObject([
['id' => 1, 'name' => 'oy'],
['id' => 2, 'name' => 'yo'],
])],
'(([[id]] = :qp0 AND [[name]] = :qp1) OR ([[id]] = :qp2 AND [[name]] = :qp3))',
[':qp0' => 1, ':qp1' => 'oy', ':qp2' => 2, ':qp3' => 'yo'],
$data = array_merge(
parent::conditionProvider(),
[
[
[
'in',
['id', 'name'],
[['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']],
],
'(([[id]] = :qp0 AND [[name]] = :qp1) OR ([[id]] = :qp2 AND [[name]] = :qp3))',
[':qp0' => 1, ':qp1' => 'foo', ':qp2' => 2, ':qp3' => 'bar'],
],
[
[
'in',
[new Expression('id'), 'name'],
[['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']],
],
'(([[id]] = :qp0 AND [[name]] = :qp1) OR ([[id]] = :qp2 AND [[name]] = :qp3))',
[':qp0' => 1, ':qp1' => 'foo', ':qp2' => 2, ':qp3' => 'bar'],
],
[
[
'not in',
['id', 'name'],
[['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']],
],
'(([[id]] != :qp0 OR [[name]] != :qp1) AND ([[id]] != :qp2 OR [[name]] != :qp3))',
[':qp0' => 1, ':qp1' => 'foo', ':qp2' => 2, ':qp3' => 'bar'],
],
//[ ['in', ['id', 'name'], (new Query())->select(['id', 'name'])->from('users')->where(['active' => 1])], 'EXISTS (SELECT 1 FROM (SELECT [[id]], [[name]] FROM [[users]] WHERE [[active]]=:qp0) AS a WHERE a.[[id]] = [[id AND a.]]name[[ = ]]name`)', [':qp0' => 1] ],
//[ ['not in', ['id', 'name'], (new Query())->select(['id', 'name'])->from('users')->where(['active' => 1])], 'NOT EXISTS (SELECT 1 FROM (SELECT [[id]], [[name]] FROM [[users]] WHERE [[active]]=:qp0) AS a WHERE a.[[id]] = [[id]] AND a.[[name = ]]name`)', [':qp0' => 1] ],
],
'composite in' => [
['in', ['id', 'name'], [['id' => 1, 'name' => 'oy']]],
'(([[id]] = :qp0 AND [[name]] = :qp1))',
[':qp0' => 1, ':qp1' => 'oy'],
);
$data['composite in'] = [
[
'in',
['id', 'name'],
[['id' => 1, 'name' => 'oy']],
],
]);
'(([[id]] = :qp0 AND [[name]] = :qp1))',
[':qp0' => 1, ':qp1' => 'oy'],
];
$data['composite in using array objects'] = [
[
'in',
new TraversableObject(['id', 'name']),
new TraversableObject([['id' => 1, 'name' => 'oy'], ['id' => 2, 'name' => 'yo']]),
],
'(([[id]] = :qp0 AND [[name]] = :qp1) OR ([[id]] = :qp2 AND [[name]] = :qp3))',
[':qp0' => 1, ':qp1' => 'oy', ':qp2' => 2, ':qp3' => 'yo'],
];
// adjust dbms specific escaping
foreach ($data as $i => $condition) {
$data[$i][1] = DbHelper::replaceQuotes($condition[1], 'sqlite');
}
return $data;
}
public function primaryKeysProvider(): void