Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Enh #372: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)
- Enh #373: Replace `DbArrayHelper::getColumn()` with `array_column()` (@Tigrov)
- New #374: Add `IndexType` and `IndexMethod` classes (@Tigrov)
- Enh #376: Move `JsonExpressionBuilder` and JSON type tests to `yiisoft/db` package (@Tigrov)
- Bug #377: Explicitly mark nullable parameters (@vjik)

## 1.2.0 March 21, 2024
Expand Down
57 changes: 0 additions & 57 deletions src/Builder/JsonExpressionBuilder.php

This file was deleted.

3 changes: 0 additions & 3 deletions src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Expression\JsonExpression;
use Yiisoft\Db\Mysql\Builder\ExpressionBuilder;
use Yiisoft\Db\Mysql\Builder\JsonExpressionBuilder;
use Yiisoft\Db\Mysql\Builder\JsonOverlapsConditionBuilder;
use Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder;
use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition;
Expand Down Expand Up @@ -83,7 +81,6 @@ protected function defaultExpressionBuilders(): array
{
return [
...parent::defaultExpressionBuilders(),
JsonExpression::class => JsonExpressionBuilder::class,
JsonOverlapsCondition::class => JsonOverlapsConditionBuilder::class,
Expression::class => ExpressionBuilder::class,
];
Expand Down
21 changes: 7 additions & 14 deletions tests/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Mysql\Tests\Provider\ColumnFactoryProvider;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Tests\AbstractColumnFactoryTest;

/**
Expand All @@ -25,23 +26,15 @@ public function testFromDbType(string $dbType, string $expectedType, string $exp
}

#[DataProviderExternal(ColumnFactoryProvider::class, 'definitions')]
public function testFromDefinition(
string $definition,
string $expectedType,
string $expectedInstanceOf,
array $expectedMethodResults = []
): void {
parent::testFromDefinition($definition, $expectedType, $expectedInstanceOf, $expectedMethodResults);
public function testFromDefinition(string $definition, ColumnInterface $expected): void
{
parent::testFromDefinition($definition, $expected);
}

#[DataProviderExternal(ColumnFactoryProvider::class, 'pseudoTypes')]
public function testFromPseudoType(
string $pseudoType,
string $expectedType,
string $expectedInstanceOf,
array $expectedMethodResults = []
): void {
parent::testFromPseudoType($pseudoType, $expectedType, $expectedInstanceOf, $expectedMethodResults);
public function testFromPseudoType(string $pseudoType, ColumnInterface $expected): void
{
parent::testFromPseudoType($pseudoType, $expected);
}

#[DataProviderExternal(ColumnFactoryProvider::class, 'types')]
Expand Down
4 changes: 2 additions & 2 deletions tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Yiisoft\Db\Schema\Column\IntegerColumn;
use Yiisoft\Db\Schema\Column\JsonColumn;
use Yiisoft\Db\Schema\Column\StringColumn;
use Yiisoft\Db\Tests\Common\CommonColumnTest;
use Yiisoft\Db\Tests\AbstractColumnTest;

use function str_repeat;

Expand All @@ -24,7 +24,7 @@
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ColumnTest extends CommonColumnTest
final class ColumnTest extends AbstractColumnTest
{
use TestTrait;

Expand Down
82 changes: 0 additions & 82 deletions tests/JsonCommandTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function definitions(): array
{
$definitions = parent::definitions();

$definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumn::class, ['getDbType' => 'bit', 'getSize' => 1]];
$definitions[] = ['bit(1)', new BooleanColumn(dbType: 'bit', size: 1)];

return $definitions;
}
Expand Down
83 changes: 1 addition & 82 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Expression\JsonExpression;
use Yiisoft\Db\Mysql\Column\ColumnBuilder;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;

use function array_replace;

Expand All @@ -27,85 +25,6 @@ public static function alterColumn(): array
];
}

public static function buildCondition(): array
{
return [
...parent::buildCondition(),
[
['=', 'jsoncol', new JsonExpression(['lang' => 'uk', 'country' => 'UA'])],
'[[jsoncol]] = :qp0', [':qp0' => '{"lang":"uk","country":"UA"}'],
],
[
['=', 'jsoncol', new JsonExpression([false])],
'[[jsoncol]] = :qp0', [':qp0' => '[false]'],
],
'object with type. Type is ignored for MySQL' => [
['=', 'prices', new JsonExpression(['seeds' => 15, 'apples' => 25], 'jsonb')],
'[[prices]] = :qp0', [':qp0' => '{"seeds":15,"apples":25}'],
],
'nested json' => [
[
'=',
'data',
new JsonExpression(
[
'user' => ['login' => 'silverfire', 'password' => 'c4ny0ur34d17?'],
'props' => ['mood' => 'good'],
]
),
],
'[[data]] = :qp0',
[':qp0' => '{"user":{"login":"silverfire","password":"c4ny0ur34d17?"},"props":{"mood":"good"}}'],
],
'null value' => [
['=', 'jsoncol', new JsonExpression(null)],
'[[jsoncol]] = :qp0', [':qp0' => 'null'],
],
'null as array value' => [
['=', 'jsoncol', new JsonExpression([null])],
'[[jsoncol]] = :qp0', [':qp0' => '[null]'],
],
'null as object value' => [
['=', 'jsoncol', new JsonExpression(['nil' => null])],
'[[jsoncol]] = :qp0', [':qp0' => '{"nil":null}'],
],
'query' => [
[
'=',
'jsoncol',
new JsonExpression((new Query(self::getDb()))->select('params')->from('user')->where(['id' => 1])),
],
'[[jsoncol]] = (SELECT [[params]] FROM [[user]] WHERE [[id]]=:qp0)',
[':qp0' => 1],
],
'query with type, that is ignored in MySQL' => [
[
'=',
'jsoncol',
new JsonExpression(
(new Query(self::getDb()))->select('params')->from('user')->where(['id' => 1]),
'jsonb'
),
],
'[[jsoncol]] = (SELECT [[params]] FROM [[user]] WHERE [[id]]=:qp0)', [':qp0' => 1],
],
'nested and combined json expression' => [
[
'=',
'jsoncol',
new JsonExpression(
new JsonExpression(['a' => 1, 'b' => 2, 'd' => new JsonExpression(['e' => 3])])
),
],
'[[jsoncol]] = :qp0', [':qp0' => '{"a":1,"b":2,"d":{"e":3}}'],
],
'search by property in JSON column (issue #15838)' => [
['=', new Expression("(jsoncol->>'$.someKey')"), '42'],
"(jsoncol->>'$.someKey') = :qp0", [':qp0' => 42],
],
];
}

public static function insert(): array
{
$insert = parent::insert();
Expand Down Expand Up @@ -213,7 +132,7 @@ public static function buildColumnDefinition(): array
$values['binary()'][0] = 'blob';
$values['binary(1000)'][0] = 'blob(1000)';
$values['uuid()'][0] = 'binary(16)';
$values["check('value > 5')"][0] = 'int CHECK (`col_59` > 5)';
$values["check('value > 5')"][0] = 'int CHECK (`check_col` > 5)';
$values["check('')"][0] = 'int';
$values['check(null)'][0] = 'int';
$values['defaultValue($expression)'][0] = 'int DEFAULT (1 + 2)';
Expand Down
Loading
Loading