Browse Source

Add QueryFactory class.

ADmad 3 years ago
parent
commit
3e98df2e5c

+ 45 - 23
src/Database/Connection.php

@@ -104,6 +104,8 @@ class Connection implements ConnectionInterface
      */
     protected ?NestedTransactionRollbackException $nestedTransactionRollbackException = null;
 
+    protected QueryFactory $queryFactory;
+
     /**
      * Constructor.
      *
@@ -279,43 +281,73 @@ class Connection implements ConnectionInterface
     }
 
     /**
+     * Get query factory instance.
+     *
+     * @return \Cake\Database\QueryFactory
+     */
+    public function queryFactory(): QueryFactory
+    {
+        return $this->queryFactory ??= new QueryFactory($this);
+    }
+
+    /**
      * Create a new SelectQuery instance for this connection.
      *
+     * @param \Cake\Database\ExpressionInterface|\Closure|array|string|float|int $fields Fields/columns list for the query.
+     * @param array|string $tables List of tables to query.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
      * @return \Cake\Database\Query\SelectQuery
      */
-    public function newSelectQuery(): SelectQuery
-    {
-        return new SelectQuery($this);
+    public function newSelectQuery(
+        ExpressionInterface|Closure|array|string|float|int $fields = [],
+        array|string $tables = [],
+        array $types = []
+    ): SelectQuery {
+        return $this->queryFactory()->select($fields, $tables, $types);
     }
 
     /**
      * Create a new InsertQuery instance for this connection.
      *
+     * @param string|null $table The table to insert rows into.
+     * @param array $values Associative array of column => value to be inserted.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
      * @return \Cake\Database\Query\InsertQuery
      */
-    public function newInsertQuery(): InsertQuery
+    public function newInsertQuery(?string $table = null, array $values = [], array $types = []): InsertQuery
     {
-        return new InsertQuery($this);
+        return $this->queryFactory()->insert($table, $values, $types);
     }
 
     /**
      * Create a new UpdateQuery instance for this connection.
      *
+     * @param string|null $table The table to update rows of.
+     * @param array $values Values to be updated.
+     * @param array $conditions Conditions to be set for the update statement.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
      * @return \Cake\Database\Query\UpdateQuery
      */
-    public function newUpdateQuery(): UpdateQuery
-    {
-        return new UpdateQuery($this);
+    public function newUpdateQuery(
+        ?string $table = null,
+        array $values = [],
+        array $conditions = [],
+        array $types = []
+    ): UpdateQuery {
+        return $this->queryFactory()->update($table, $values, $conditions, $types);
     }
 
     /**
      * Create a new DeleteQuery instance for this connection.
      *
+     * @param string|null $table The table to delete rows from.
+     * @param array $conditions Conditions to be set for the delete statement.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
      * @return \Cake\Database\Query\DeleteQuery
      */
-    public function newDeleteQuery(): DeleteQuery
+    public function newDeleteQuery(?string $table = null, array $conditions = [], array $types = []): DeleteQuery
     {
-        return new DeleteQuery($this);
+        return $this->queryFactory()->delete($table, $conditions, $types);
     }
 
     /**
@@ -363,12 +395,7 @@ class Connection implements ConnectionInterface
      */
     public function insert(string $table, array $values, array $types = []): StatementInterface
     {
-        $columns = array_keys($values);
-
-        return $this->newInsertQuery()->insert($columns, $types)
-            ->into($table)
-            ->values($values)
-            ->execute();
+        return $this->newInsertQuery($table, $values)->execute();
     }
 
     /**
@@ -382,10 +409,7 @@ class Connection implements ConnectionInterface
      */
     public function update(string $table, array $values, array $conditions = [], array $types = []): StatementInterface
     {
-        return $this->newUpdateQuery()->update($table)
-            ->set($values, $types)
-            ->where($conditions, $types)
-            ->execute();
+        return $this->newUpdateQuery($table, $values, $conditions, $types)->execute();
     }
 
     /**
@@ -398,9 +422,7 @@ class Connection implements ConnectionInterface
      */
     public function delete(string $table, array $conditions = [], array $types = []): StatementInterface
     {
-        return $this->newDeleteQuery()->delete($table)
-            ->where($conditions, $types)
-            ->execute();
+        return $this->newDeleteQuery($table, $conditions, $types)->execute();
     }
 
     /**

+ 138 - 0
src/Database/QueryFactory.php

@@ -0,0 +1,138 @@
+<?php
+declare(strict_types=1);
+
+/**
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ * @link          https://cakephp.org CakePHP(tm) Project
+ * @since         5.0.0
+ * @license       https://opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Database;
+
+use Cake\Database\Query\DeleteQuery;
+use Cake\Database\Query\InsertQuery;
+use Cake\Database\Query\SelectQuery;
+use Cake\Database\Query\UpdateQuery;
+use Closure;
+
+/**
+ * Factory class for generating instances of Select, Insert, Update, Delete queries.
+ */
+class QueryFactory
+{
+    /**
+     * Constructor/
+     *
+     * @param \Cake\Database\Connection $connection Connection instance.
+     */
+    public function __construct(
+        protected Connection $connection,
+    ) {
+    }
+
+    /**
+     * Create a new SelectQuery instance.
+     *
+     * @param \Cake\Database\ExpressionInterface|\Closure|array|string|float|int $fields Fields/columns list for the query.
+     * @param array|string $tables List of tables to query.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
+     * @return \Cake\Database\Query\SelectQuery
+     */
+    public function select(
+        ExpressionInterface|Closure|array|string|float|int $fields = [],
+        array|string $tables = [],
+        array $types = []
+    ): SelectQuery {
+        $query = new SelectQuery($this->connection);
+
+        $query
+            ->select($fields)
+            ->from($tables)
+            ->setDefaultTypes($types);
+
+        return $query;
+    }
+
+    /**
+     * Create a new InsertQuery instance.
+     *
+     * @param string|null $table The table to insert rows into.
+     * @param array $values Associative array of column => value to be inserted.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
+     * @return \Cake\Database\Query\InsertQuery
+     */
+    public function insert(?string $table = null, array $values = [], array $types = []): InsertQuery
+    {
+        $query = new InsertQuery($this->connection);
+
+        if ($table) {
+            $query->into($table);
+        }
+
+        if ($values) {
+            $columns = array_keys($values);
+            $query
+                ->insert($columns, $types)
+                ->values($values);
+        }
+
+        return $query;
+    }
+
+    /**
+     * Create a new UpdateQuery instance.
+     *
+     * @param string|null $table The table to update rows of.
+     * @param array $values Values to be updated.
+     * @param array $conditions Conditions to be set for the update statement.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
+     * @return \Cake\Database\Query\UpdateQuery
+     */
+    public function update(
+        ?string $table = null,
+        array $values = [],
+        array $conditions = [],
+        array $types = []
+    ): UpdateQuery {
+        $query = new UpdateQuery($this->connection);
+
+        if ($table) {
+            $query->update($table);
+        }
+        if ($values) {
+            $query->set($values, $types);
+        }
+        if ($conditions) {
+            $query->where($conditions, $types);
+        }
+
+        return $query;
+    }
+
+    /**
+     * Create a new DeleteQuery instance.
+     *
+     * @param string|null $table The table to delete rows from.
+     * @param array $conditions Conditions to be set for the delete statement.
+     * @param array<string, string> $types Associative array containing the types to be used for casting.
+     * @return \Cake\Database\Query\DeleteQuery
+     */
+    public function delete(?string $table = null, array $conditions = [], array $types = []): DeleteQuery
+    {
+        $query = (new DeleteQuery($this->connection))
+            ->delete($table);
+
+        if ($conditions) {
+            $query->where($conditions, $types);
+        }
+
+        return $query;
+    }
+}

+ 5 - 5
tests/TestCase/Database/Expression/CaseStatementExpressionTest.php

@@ -1341,7 +1341,7 @@ class CaseStatementExpressionTest extends TestCase
             [Chronos::now(), null, 'datetime'],
             [new IdentifierExpression('Table.column'), 'Table.column', null],
             [new QueryExpression('Table.column'), 'Table.column', null],
-            [ConnectionManager::get('test')->newSelectQuery()->select('a'), '(SELECT a)', null],
+            [ConnectionManager::get('test')->newSelectQuery('a'), '(SELECT a)', null],
             [new TestObjectWithToString(), null, 'string'],
             [new stdClass(), null, null],
         ];
@@ -1459,7 +1459,7 @@ class CaseStatementExpressionTest extends TestCase
                 ],
             ],
             [
-                ConnectionManager::get('test')->newSelectQuery()->select('a'),
+                ConnectionManager::get('test')->newSelectQuery('a'),
                 'CASE :c0 WHEN (SELECT a) THEN :c1 ELSE NULL END',
                 [
                     ':c0' => [
@@ -1591,7 +1591,7 @@ class CaseStatementExpressionTest extends TestCase
                 ],
             ],
             [
-                ConnectionManager::get('test')->newSelectQuery()->select('a'),
+                ConnectionManager::get('test')->newSelectQuery('a'),
                 'CASE WHEN (SELECT a) THEN :c0 ELSE NULL END',
                 [
                     ':c0' => [
@@ -1686,7 +1686,7 @@ class CaseStatementExpressionTest extends TestCase
             [Chronos::now(), null, 'datetime'],
             [new IdentifierExpression('Table.column'), 'Table.column', null],
             [new QueryExpression('Table.column'), 'Table.column', null],
-            [ConnectionManager::get('test')->newSelectQuery()->select('a'), '(SELECT a)', null],
+            [ConnectionManager::get('test')->newSelectQuery('a'), '(SELECT a)', null],
             [new TestObjectWithToString(), null, 'string'],
             [new stdClass(), null, null],
         ];
@@ -1762,7 +1762,7 @@ class CaseStatementExpressionTest extends TestCase
             [Chronos::now(), null, 'datetime'],
             [new IdentifierExpression('Table.column'), 'Table.column', null],
             [new QueryExpression('Table.column'), 'Table.column', null],
-            [ConnectionManager::get('test')->newSelectQuery()->select('a'), '(SELECT a)', null],
+            [ConnectionManager::get('test')->newSelectQuery('a'), '(SELECT a)', null],
             [new TestObjectWithToString(), null, 'string'],
             [new stdClass(), null, null],
         ];

+ 3 - 3
tests/TestCase/Database/Expression/CommonTableExpressionTest.php

@@ -100,7 +100,7 @@ class CommonTableExpressionTest extends TestCase
         $this->assertEqualsSql('test AS ()', $cte->sql(new ValueBinder()));
 
         $cte->query(function () {
-            return $this->connection->newSelectQuery()->select('1');
+            return $this->connection->newSelectQuery('1');
         });
         $this->assertEqualsSql('test AS (SELECT 1)', $cte->sql(new ValueBinder()));
     }
@@ -110,7 +110,7 @@ class CommonTableExpressionTest extends TestCase
      */
     public function testTraverse(): void
     {
-        $query = $this->connection->newSelectQuery()->select('1');
+        $query = $this->connection->newSelectQuery('1');
         $cte = (new CommonTableExpression('test', $query))->field('field');
 
         $expressions = [];
@@ -129,7 +129,7 @@ class CommonTableExpressionTest extends TestCase
     public function testClone(): void
     {
         $cte = new CommonTableExpression('test', function () {
-            return $this->connection->newSelectQuery()->select('1');
+            return $this->connection->newSelectQuery('1');
         });
         $cte2 = (clone $cte)->name('test2');
         $this->assertNotSame($cte->sql(new ValueBinder()), $cte2->sql(new ValueBinder()));

+ 1 - 2
tests/TestCase/Database/Expression/FunctionExpressionTest.php

@@ -99,8 +99,7 @@ class FunctionExpressionTest extends TestCase
     public function testFunctionWithDatabaseQuery(): void
     {
         $query = ConnectionManager::get('test')
-            ->newSelectQuery()
-            ->select(['column']);
+            ->newSelectQuery(['column']);
 
         $binder = new ValueBinder();
         $function = new $this->expressionClass('MyFunction', [$query]);

+ 6 - 18
tests/TestCase/Database/ExpressionTypeCastingIntegrationTest.php

@@ -65,9 +65,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testInsert(): void
     {
         $this->_insert();
-        $query = $this->connection->newSelectQuery()
-            ->select('id')
-            ->from('ordered_uuid_items')
+        $query = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
             ->order('id')
             ->setDefaultTypes(['id' => 'ordered_uuid']);
 
@@ -85,9 +83,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithConditions(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery()
-            ->select('id')
-            ->from('ordered_uuid_items')
+        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
             ->where(['id' => '48298a29-81c0-4c26-a7fb-413140cf8569'], ['id' => 'ordered_uuid'])
             ->execute()
             ->fetchAll('assoc');
@@ -102,9 +98,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithConditionsValueObject(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery()
-            ->select('id')
-            ->from('ordered_uuid_items')
+        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
             ->where(['id' => new UuidValue('48298a29-81c0-4c26-a7fb-413140cf8569')], ['id' => 'ordered_uuid'])
             ->execute()
             ->fetchAll('assoc');
@@ -121,9 +115,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithInCondition(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery()
-            ->select('id')
-            ->from('ordered_uuid_items')
+        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
             ->where(
                 ['id' => ['48298a29-81c0-4c26-a7fb-413140cf8569', '482b7756-8da0-419a-b21f-27da40cf8569']],
                 ['id' => 'ordered_uuid[]']
@@ -143,9 +135,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithBetween(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery()
-            ->select('id')
-            ->from('ordered_uuid_items')
+        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
             ->where(function (QueryExpression $exp) {
                 return $exp->between(
                     'id',
@@ -166,9 +156,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithFunction(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery()
-            ->select('id')
-            ->from('ordered_uuid_items')
+        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
             ->where(function (QueryExpression $exp, Query $q) {
                 return $exp->eq(
                     'id',

+ 15 - 38
tests/TestCase/Database/QueryTests/CommonTableExpressionQueryTest.php

@@ -72,7 +72,7 @@ class CommonTableExpressionQueryTest extends TestCase
     {
         $query = $this->connection->newSelectQuery()
             ->with(new CommonTableExpression('cte', function () {
-                return $this->connection->newSelectQuery()->select(['col' => 1]);
+                return $this->connection->newSelectQuery(['col' => 1]);
             }))
             ->select('col')
             ->from('cte');
@@ -101,7 +101,7 @@ class CommonTableExpressionQueryTest extends TestCase
     {
         $query = $this->connection->newSelectQuery()
             ->with(new CommonTableExpression('cte', function () {
-                return $this->connection->newSelectQuery()->select(['col' => '1']);
+                return $this->connection->newSelectQuery(['col' => '1']);
             }))
             ->select('col')
             ->from('cte');
@@ -130,11 +130,9 @@ class CommonTableExpressionQueryTest extends TestCase
                 $anchorQuery = $query->select(1);
 
                 $recursiveQuery = $query->getConnection()
-                    ->newSelectQuery()
-                    ->select(function (Query $query) {
+                    ->newSelectQuery(function (Query $query) {
                         return $query->newExpr('col + 1');
-                    })
-                    ->from('cte')
+                    }, 'cte')
                     ->where(['col !=' => 3], ['col' => 'integer']);
 
                 $cteQuery = $anchorQuery->unionAll($recursiveQuery);
@@ -197,9 +195,7 @@ class CommonTableExpressionQueryTest extends TestCase
         );
 
         // test initial state
-        $result = $this->connection->newSelectQuery()
-            ->select('*')
-            ->from('articles')
+        $result = $this->connection->newSelectQuery('*', 'articles')
             ->where(['id' => 4])
             ->execute();
         $this->assertFalse($result->fetch('assoc'));
@@ -217,9 +213,7 @@ class CommonTableExpressionQueryTest extends TestCase
             ->into('articles')
             ->values(
                 $this->connection
-                    ->newSelectQuery()
-                    ->select('*')
-                    ->from('cte')
+                    ->newSelectQuery('*', 'cte')
             );
 
         $this->assertRegExpSql(
@@ -241,9 +235,7 @@ class CommonTableExpressionQueryTest extends TestCase
         ];
 
         // test updated state
-        $result = $this->connection->newSelectQuery()
-            ->select('*')
-            ->from('articles')
+        $result = $this->connection->newSelectQuery('*', 'articles')
             ->where(['id' => 4])
             ->execute();
         $this->assertEquals($expected, $result->fetch('assoc'));
@@ -260,9 +252,8 @@ class CommonTableExpressionQueryTest extends TestCase
             '`INSERT INTO ... WITH` syntax is not supported in SQL Server.'
         );
 
-        $query = $this->connection->newInsertQuery()
+        $query = $this->connection->newInsertQuery('articles')
             ->insert(['title', 'body'])
-            ->into('articles')
             ->values(
                 $this->connection->newSelectQuery()
                     ->with(function (CommonTableExpression $cte, SelectQuery $query) {
@@ -294,9 +285,7 @@ class CommonTableExpressionQueryTest extends TestCase
         ];
 
         // test updated state
-        $result = $this->connection->newSelectQuery()
-            ->select('*')
-            ->from('articles')
+        $result = $this->connection->newSelectQuery('*', 'articles')
             ->where(['id' => 4])
             ->execute();
         $this->assertEquals($expected, $result->fetch('assoc'));
@@ -314,9 +303,7 @@ class CommonTableExpressionQueryTest extends TestCase
         );
 
         // test initial state
-        $result = $this->connection->newSelectQuery()
-            ->select(['count' => 'COUNT(*)'])
-            ->from('articles')
+        $result = $this->connection->newSelectQuery(['count' => 'COUNT(*)'], 'articles')
             ->where(['published' => 'Y'])
             ->execute();
         $this->assertEquals(['count' => '3'], $result->fetch('assoc'));
@@ -340,9 +327,7 @@ class CommonTableExpressionQueryTest extends TestCase
                     'articles.id',
                     $query
                         ->getConnection()
-                        ->newSelectQuery()
-                        ->select('cte.id')
-                        ->from('cte')
+                        ->newSelectQuery('cte.id', 'cte')
                 );
             });
 
@@ -356,9 +341,7 @@ class CommonTableExpressionQueryTest extends TestCase
         $query->execute()->closeCursor();
 
         // test updated state
-        $result = $this->connection->newSelectQuery()
-            ->select(['count' => 'COUNT(*)'])
-            ->from('articles')
+        $result = $this->connection->newSelectQuery(['count' => 'COUNT(*)'], 'articles')
             ->where(['published' => 'Y'])
             ->execute();
         $this->assertEquals(['count' => '1'], $result->fetch('assoc'));
@@ -377,9 +360,7 @@ class CommonTableExpressionQueryTest extends TestCase
 
         // test initial state
         $result = $this->connection
-            ->newSelectQuery()
-            ->select(['count' => 'COUNT(*)'])
-            ->from('articles')
+            ->newSelectQuery(['count' => 'COUNT(*)'], 'articles')
             ->execute();
         $this->assertEquals(['count' => '3'], $result->fetch('assoc'));
         $result->closeCursor();
@@ -401,9 +382,7 @@ class CommonTableExpressionQueryTest extends TestCase
                     'a.id',
                     $query
                         ->getConnection()
-                        ->newSelectQuery()
-                        ->select('cte.id')
-                        ->from('cte')
+                        ->newSelectQuery('cte.id', 'cte')
                 );
             });
 
@@ -425,9 +404,7 @@ class CommonTableExpressionQueryTest extends TestCase
         ];
 
         // test updated state
-        $result = $this->connection->newSelectQuery()
-            ->select('*')
-            ->from('articles')
+        $result = $this->connection->newSelectQuery('*', 'articles')
             ->execute();
         $this->assertEquals($expected, $result->fetch('assoc'));
         $result->closeCursor();

+ 25 - 20
tests/TestCase/Database/QueryTests/TupleComparisonQueryTest.php

@@ -95,10 +95,11 @@ class TupleComparisonQueryTest extends TestCase
             ->where([
                 new TupleComparison(
                     ['articles.id', 'articles.author_id'],
-                    $this->connection->newSelectQuery()
-                        ->select(['ArticlesAlias.id', 'ArticlesAlias.author_id'])
-                        ->from(['ArticlesAlias' => 'articles'])
-                        ->where(['ArticlesAlias.author_id' => 1]),
+                    $this->connection->newSelectQuery(
+                        ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
+                        ['ArticlesAlias' => 'articles']
+                    )
+                    ->where(['ArticlesAlias.author_id' => 1]),
                     [],
                     'NOT IN'
                 ),
@@ -120,10 +121,11 @@ class TupleComparisonQueryTest extends TestCase
             ->where([
                 new TupleComparison(
                     ['articles.id', 'articles.author_id'],
-                    $this->connection->newSelectQuery()
-                        ->select(['ArticlesAlias.id', 'ArticlesAlias.author_id'])
-                        ->from(['ArticlesAlias' => 'articles'])
-                        ->where(['ArticlesAlias.author_id' => 1]),
+                    $this->connection->newSelectQuery(
+                        ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
+                        ['ArticlesAlias' => 'articles']
+                    )
+                    ->where(['ArticlesAlias.author_id' => 1]),
                     [],
                     'IN'
                 ),
@@ -157,10 +159,11 @@ class TupleComparisonQueryTest extends TestCase
             ->where([
                 new TupleComparison(
                     ['articles.id', 'articles.author_id'],
-                    $this->connection->newSelectQuery()
-                        ->select(['ArticlesAlias.id', 'ArticlesAlias.author_id'])
-                        ->from(['ArticlesAlias' => 'articles'])
-                        ->where(['ArticlesAlias.id' => 1]),
+                    $this->connection->newSelectQuery(
+                        ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
+                        ['ArticlesAlias' => 'articles']
+                    )
+                    ->where(['ArticlesAlias.id' => 1]),
                     [],
                     'IN'
                 ),
@@ -233,10 +236,11 @@ class TupleComparisonQueryTest extends TestCase
             ->where([
                 new TupleComparison(
                     ['articles.id', 'articles.author_id'],
-                    $this->connection->newSelectQuery()
-                        ->select(['ArticlesAlias.id', 'ArticlesAlias.author_id'])
-                        ->from(['ArticlesAlias' => 'articles'])
-                        ->where(['ArticlesAlias.author_id' => 1]),
+                    $this->connection->newSelectQuery(
+                        ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
+                        ['ArticlesAlias' => 'articles']
+                    )
+                    ->where(['ArticlesAlias.author_id' => 1]),
                     [],
                     '='
                 ),
@@ -258,10 +262,11 @@ class TupleComparisonQueryTest extends TestCase
             ->where([
                 new TupleComparison(
                     ['articles.id', 'articles.author_id'],
-                    $this->connection->newSelectQuery()
-                        ->select(['ArticlesAlias.id', 'ArticlesAlias.author_id'])
-                        ->from(['ArticlesAlias' => 'articles'])
-                        ->where(['ArticlesAlias.id' => 1]),
+                    $this->connection->newSelectQuery(
+                        ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
+                        ['ArticlesAlias' => 'articles']
+                    )
+                    ->where(['ArticlesAlias.id' => 1]),
                     [],
                     '='
                 ),