66
77use ArrayIterator ;
88use PHPUnit \Framework \Attributes \DataProvider ;
9- use PHPUnit \Framework \TestCase ;
109use Yiisoft \Db \Constant \ColumnType ;
1110use Yiisoft \Db \Constant \DataType ;
1211use Yiisoft \Db \Expression \Value \ArrayValue ;
1817use Yiisoft \Db \Pgsql \Column \ColumnBuilder ;
1918use Yiisoft \Db \Pgsql \Data \LazyArray ;
2019use Yiisoft \Db \Pgsql \Data \StructuredLazyArray ;
21- use Yiisoft \Db \Pgsql \Tests \Support \TestTrait ;
20+ use Yiisoft \Db \Pgsql \Tests \Support \IntegrationTestTrait ;
2221use Yiisoft \Db \Query \Query ;
2322use Yiisoft \Db \Schema \Column \ColumnInterface ;
2423use Yiisoft \Db \Schema \Data \JsonLazyArray ;
2524use Yiisoft \Db \Schema \Data \LazyArrayInterface ;
2625use Yiisoft \Db \Tests \Support \Assert ;
26+ use Yiisoft \Db \Tests \Support \IntegrationTestCase ;
2727
2828/**
2929 * @group pgsql
3030 */
31- final class ArrayValueBuilderTest extends TestCase
31+ final class ArrayValueBuilderTest extends IntegrationTestCase
3232{
33- use TestTrait ;
33+ use IntegrationTestTrait ;
3434
3535 public static function buildProvider (): array
3636 {
@@ -127,16 +127,6 @@ public static function buildProvider(): array
127127 'ARRAY[NULL,ROW(11.11,:qp0),ROW(NULL,NULL)] ' ,
128128 [':qp0 ' => new Param ('USD ' , DataType::STRING )],
129129 ],
130- 'Query w/o type ' => [
131- (new Query (self ::getDb ()))->select ('id ' )->from ('users ' )->where (['active ' => 1 ]),
132- null ,
133- 'ARRAY(SELECT "id" FROM "users" WHERE "active" = 1) ' ,
134- ],
135- 'Query ' => [
136- [(new Query (self ::getDb ()))->select ('id ' )->from ('users ' )->where (['active ' => 1 ])],
137- 'integer[][] ' ,
138- 'ARRAY[ARRAY(SELECT "id" FROM "users" WHERE "active" = 1)::integer[]]::integer[][] ' ,
139- ],
140130 'bool ' => [
141131 [[[true ], [false , null ]], [['t ' , 'f ' ], null ], null ],
142132 'bool[][][] ' ,
@@ -169,7 +159,7 @@ public function testBuild(
169159 string $ expected ,
170160 array $ expectedParams = [],
171161 ): void {
172- $ db = $ this ->getConnection ();
162+ $ db = $ this ->getSharedConnection ();
173163 $ qb = $ db ->getQueryBuilder ();
174164
175165 $ params = [];
@@ -178,7 +168,40 @@ public function testBuild(
178168
179169 $ this ->assertSame ($ expected , $ builder ->build ($ expression , $ params ));
180170 Assert::arraysEquals ($ expectedParams , $ params );
171+ }
172+
173+ public function testBuildWithQuery (): void
174+ {
175+ $ db = $ this ->getSharedConnection ();
176+ $ queryBuilder = $ db ->getQueryBuilder ();
177+
178+ $ params = [];
179+ $ builder = new ArrayValueBuilder ($ queryBuilder );
180+ $ expression = new ArrayValue (
181+ $ db ->select ('id ' )->from ('users ' )->where (['active ' => 1 ]),
182+ );
183+
184+ $ result = $ builder ->build ($ expression , $ params );
185+
186+ $ this ->assertSame ('ARRAY(SELECT "id" FROM "users" WHERE "active" = 1) ' , $ result );
187+ $ this ->assertSame ([], $ params );
188+ }
189+
190+ public function testBuildWithArrayOfQuery (): void
191+ {
192+ $ db = $ this ->getSharedConnection ();
193+ $ queryBuilder = $ db ->getQueryBuilder ();
194+
195+ $ params = [];
196+ $ builder = new ArrayValueBuilder ($ queryBuilder );
197+ $ expression = new ArrayValue (
198+ [$ db ->select ('id ' )->from ('users ' )->where (['active ' => 1 ])],
199+ 'integer[][] ' ,
200+ );
201+
202+ $ result = $ builder ->build ($ expression , $ params );
181203
182- $ db ->close ();
204+ $ this ->assertSame ('ARRAY[ARRAY(SELECT "id" FROM "users" WHERE "active" = 1)::integer[]]::integer[][] ' , $ result );
205+ $ this ->assertSame ([], $ params );
183206 }
184207}
0 commit comments