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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"vimeo/psalm": "^5.26.1 || ^6.8.8",
"vlucas/phpdotenv": "^5.6.1",
"yiisoft/aliases": "^2.0",
"yiisoft/cache-file": "^3.2",
"yiisoft/psr-dummy-provider": "^1.0",
"yiisoft/test-support": "^3.0",
"yiisoft/var-dumper": "^1.7"
},
"provide": {
Expand Down
55 changes: 39 additions & 16 deletions tests/ArrayValueBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use ArrayIterator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\DataType;
use Yiisoft\Db\Expression\Value\ArrayValue;
Expand All @@ -18,19 +17,20 @@
use Yiisoft\Db\Pgsql\Column\ColumnBuilder;
use Yiisoft\Db\Pgsql\Data\LazyArray;
use Yiisoft\Db\Pgsql\Data\StructuredLazyArray;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\Data\JsonLazyArray;
use Yiisoft\Db\Schema\Data\LazyArrayInterface;
use Yiisoft\Db\Tests\Support\Assert;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

/**
* @group pgsql
*/
final class ArrayValueBuilderTest extends TestCase
final class ArrayValueBuilderTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public static function buildProvider(): array
{
Expand Down Expand Up @@ -127,16 +127,6 @@ public static function buildProvider(): array
'ARRAY[NULL,ROW(11.11,:qp0),ROW(NULL,NULL)]',
[':qp0' => new Param('USD', DataType::STRING)],
],
'Query w/o type' => [
(new Query(self::getDb()))->select('id')->from('users')->where(['active' => 1]),
null,
'ARRAY(SELECT "id" FROM "users" WHERE "active" = 1)',
],
'Query' => [
[(new Query(self::getDb()))->select('id')->from('users')->where(['active' => 1])],
'integer[][]',
'ARRAY[ARRAY(SELECT "id" FROM "users" WHERE "active" = 1)::integer[]]::integer[][]',
],
'bool' => [
[[[true], [false, null]], [['t', 'f'], null], null],
'bool[][][]',
Expand Down Expand Up @@ -169,7 +159,7 @@ public function testBuild(
string $expected,
array $expectedParams = [],
): void {
$db = $this->getConnection();
$db = $this->getSharedConnection();
$qb = $db->getQueryBuilder();

$params = [];
Expand All @@ -178,7 +168,40 @@ public function testBuild(

$this->assertSame($expected, $builder->build($expression, $params));
Assert::arraysEquals($expectedParams, $params);
}

public function testBuildWithQuery(): void
{
$db = $this->getSharedConnection();
$queryBuilder = $db->getQueryBuilder();

$params = [];
$builder = new ArrayValueBuilder($queryBuilder);
$expression = new ArrayValue(
$db->select('id')->from('users')->where(['active' => 1]),
);

$result = $builder->build($expression, $params);

$this->assertSame('ARRAY(SELECT "id" FROM "users" WHERE "active" = 1)', $result);
$this->assertSame([], $params);
}

public function testBuildWithArrayOfQuery(): void
{
$db = $this->getSharedConnection();
$queryBuilder = $db->getQueryBuilder();

$params = [];
$builder = new ArrayValueBuilder($queryBuilder);
$expression = new ArrayValue(
[$db->select('id')->from('users')->where(['active' => 1])],
'integer[][]',
);

$result = $builder->build($expression, $params);

$db->close();
$this->assertSame('ARRAY[ARRAY(SELECT "id" FROM "users" WHERE "active" = 1)::integer[]]::integer[][]', $result);
$this->assertSame([], $params);
}
}
6 changes: 2 additions & 4 deletions tests/BatchQueryResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace Yiisoft\Db\Pgsql\Tests;

use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Common\CommonBatchQueryResultTest;

/**
* @group pgsql
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class BatchQueryResultTest extends CommonBatchQueryResultTest
{
use TestTrait;
use IntegrationTestTrait;
}
17 changes: 8 additions & 9 deletions tests/Column/DateMultiRangeColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

use DateTimeImmutable;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Expression\DateRangeValue;
use Yiisoft\Db\Pgsql\Expression\MultiRangeValue;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\TestConnection;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

final class DateMultiRangeColumnTest extends TestCase
final class DateMultiRangeColumnTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public static function dataBase(): iterable
{
Expand Down Expand Up @@ -105,7 +104,7 @@ public static function dataBase(): iterable
#[DataProvider('dataBase')]
public function testBase(mixed $expectedColumnValue, mixed $value): void
{
$db = $this->createConnection(['{[2024-01-01,2024-01-10),[2024-01-20,2024-01-30]}', '{[2024-02-01,2024-02-10)}']);
$db = $this->prepareConnection(['{[2024-01-01,2024-01-10),[2024-01-20,2024-01-30]}', '{[2024-02-01,2024-02-10)}']);

$db->createCommand()->insert('tbl_test', ['col' => $value])->execute();

Expand Down Expand Up @@ -137,7 +136,7 @@ public static function dataPhpTypecast(): iterable
#[DataProvider('dataPhpTypecast')]
public function testPhpTypecast(array $expected, string $value): void
{
$db = $this->createConnection([$value]);
$db = $this->prepareConnection([$value]);

$result = $db->select('col')->from('tbl_test')->where(['id' => 1])->withTypecasting()->one();

Expand All @@ -147,9 +146,9 @@ public function testPhpTypecast(array $expected, string $value): void
/**
* @psalm-param list<string> $values
*/
private function createConnection(array $values = []): Connection
private function prepareConnection(array $values = []): Connection
{
$db = TestConnection::get();
$db = $this->getSharedConnection();
$this->ensureMinPostgreSqlVersion('14.0');

$db->createCommand('DROP TABLE IF EXISTS tbl_test')->execute();
Expand Down
17 changes: 8 additions & 9 deletions tests/Column/DateRangeColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

use DateTimeImmutable;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Expression\DateRangeValue;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\TestConnection;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

final class DateRangeColumnTest extends TestCase
final class DateRangeColumnTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public static function dataBase(): iterable
{
Expand Down Expand Up @@ -77,7 +76,7 @@ public static function dataBase(): iterable
#[DataProvider('dataBase')]
public function testBase(mixed $expectedColumnValue, mixed $value): void
{
$db = $this->createConnection(['[2024-01-01,2024-01-10)', '(2024-01-20,2024-01-30]']);
$db = $this->prepareConnection(['[2024-01-01,2024-01-10)', '(2024-01-20,2024-01-30]']);

$db->createCommand()->insert('tbl_test', ['col' => $value])->execute();

Expand Down Expand Up @@ -107,7 +106,7 @@ public static function dataPhpTypecast(): iterable
#[DataProvider('dataPhpTypecast')]
public function testPhpTypecast(mixed $expected, string $value): void
{
$db = $this->createConnection([$value]);
$db = $this->prepareConnection([$value]);

$result = $db->select('col')->from('tbl_test')->where(['id' => 1])->withTypecasting()->one();

Expand All @@ -117,9 +116,9 @@ public function testPhpTypecast(mixed $expected, string $value): void
/**
* @psalm-param list<string> $values
*/
private function createConnection(array $values = []): Connection
private function prepareConnection(array $values = []): Connection
{
$db = TestConnection::get();
$db = $this->getSharedConnection();

$db->createCommand('DROP TABLE IF EXISTS tbl_test')->execute();
$db->createCommand(
Expand Down
17 changes: 8 additions & 9 deletions tests/Column/Int4MultiRangeColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
namespace Yiisoft\Db\Pgsql\Tests\Column;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Expression\Int4RangeValue;
use Yiisoft\Db\Pgsql\Expression\MultiRangeValue;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\TestConnection;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

final class Int4MultiRangeColumnTest extends TestCase
final class Int4MultiRangeColumnTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public static function dataBase(): iterable
{
Expand Down Expand Up @@ -53,7 +52,7 @@ public static function dataBase(): iterable
#[DataProvider('dataBase')]
public function testBase(mixed $expectedColumnValue, mixed $value): void
{
$db = $this->createConnection(['{[1,10),[20,30]}', '{[40,50)}']);
$db = $this->prepareConnection(['{[1,10),[20,30]}', '{[40,50)}']);

$db->createCommand()->insert('tbl_test', ['col' => $value])->execute();

Expand Down Expand Up @@ -85,7 +84,7 @@ public static function dataPhpTypecast(): iterable
#[DataProvider('dataPhpTypecast')]
public function testPhpTypecast(array $expected, string $value): void
{
$db = $this->createConnection([$value]);
$db = $this->prepareConnection([$value]);

$result = $db->select('col')->from('tbl_test')->where(['id' => 1])->withTypecasting()->one();

Expand All @@ -95,9 +94,9 @@ public function testPhpTypecast(array $expected, string $value): void
/**
* @psalm-param list<string> $values
*/
private function createConnection(array $values = []): Connection
private function prepareConnection(array $values = []): Connection
{
$db = TestConnection::get();
$db = $this->getSharedConnection();
$this->ensureMinPostgreSqlVersion('14.0');

$db->createCommand('DROP TABLE IF EXISTS tbl_test')->execute();
Expand Down
17 changes: 8 additions & 9 deletions tests/Column/Int4RangeColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
namespace Yiisoft\Db\Pgsql\Tests\Column;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Expression\Int4RangeValue;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\TestConnection;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

final class Int4RangeColumnTest extends TestCase
final class Int4RangeColumnTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public static function dataBase(): iterable
{
Expand Down Expand Up @@ -43,7 +42,7 @@ public static function dataBase(): iterable
#[DataProvider('dataBase')]
public function testBase(mixed $expectedColumnValue, mixed $value): void
{
$db = $this->createConnection(['[1,10)', '(20,30]']);
$db = $this->prepareConnection(['[1,10)', '(20,30]']);

$db->createCommand()->insert('tbl_test', ['col' => $value])->execute();

Expand Down Expand Up @@ -73,7 +72,7 @@ public static function dataPhpTypecast(): iterable
#[DataProvider('dataPhpTypecast')]
public function testPhpTypecast(mixed $expected, string $value): void
{
$db = $this->createConnection([$value]);
$db = $this->prepareConnection([$value]);

$result = $db->select('col')->from('tbl_test')->where(['id' => 1])->withTypecasting()->one();

Expand All @@ -83,9 +82,9 @@ public function testPhpTypecast(mixed $expected, string $value): void
/**
* @psalm-param list<string> $values
*/
private function createConnection(array $values = []): Connection
private function prepareConnection(array $values = []): Connection
{
$db = TestConnection::get();
$db = $this->getSharedConnection();

$db->createCommand('DROP TABLE IF EXISTS tbl_test')->execute();
$db->createCommand(
Expand Down
17 changes: 8 additions & 9 deletions tests/Column/Int8MultiRangeColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
namespace Yiisoft\Db\Pgsql\Tests\Column;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Expression\Int8RangeValue;
use Yiisoft\Db\Pgsql\Expression\MultiRangeValue;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Pgsql\Tests\TestConnection;
use Yiisoft\Db\Pgsql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

final class Int8MultiRangeColumnTest extends TestCase
final class Int8MultiRangeColumnTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public static function dataBase(): iterable
{
Expand Down Expand Up @@ -53,7 +52,7 @@ public static function dataBase(): iterable
#[DataProvider('dataBase')]
public function testBase(mixed $expectedColumnValue, mixed $value): void
{
$db = $this->createConnection(['{[1,10),[20,30]}', '{[40,50)}']);
$db = $this->prepareConnection(['{[1,10),[20,30]}', '{[40,50)}']);

$db->createCommand()->insert('tbl_test', ['col' => $value])->execute();

Expand Down Expand Up @@ -85,7 +84,7 @@ public static function dataPhpTypecast(): iterable
#[DataProvider('dataPhpTypecast')]
public function testPhpTypecast(array $expected, string $value): void
{
$db = $this->createConnection([$value]);
$db = $this->prepareConnection([$value]);

$result = $db->select('col')->from('tbl_test')->where(['id' => 1])->withTypecasting()->one();

Expand All @@ -95,9 +94,9 @@ public function testPhpTypecast(array $expected, string $value): void
/**
* @psalm-param list<string> $values
*/
private function createConnection(array $values = []): Connection
private function prepareConnection(array $values = []): Connection
{
$db = TestConnection::get();
$db = $this->getSharedConnection();
$this->ensureMinPostgreSqlVersion('14.0');

$db->createCommand('DROP TABLE IF EXISTS tbl_test')->execute();
Expand Down
Loading
Loading