Browse Source

Add tests that cover named parameter public API

If we are going to document using named parameters we need to have tests
for it or we will eventually regress on this.
Mark Story 3 years ago
parent
commit
d60a85aa5e

+ 1 - 1
src/Database/Connection.php

@@ -303,7 +303,7 @@ class Connection implements ConnectionInterface
         array|string $table = [],
         array $types = []
     ): SelectQuery {
-        return $this->queryFactory()->select($fields, $tables, $types);
+        return $this->queryFactory()->select($fields, $table, $types);
     }
 
     /**

+ 2 - 2
tests/TestCase/Database/ExpressionTypeCastingIntegrationTest.php

@@ -135,7 +135,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithBetween(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
+        $result = $this->connection->newSelectQuery(fields: 'id', table: 'ordered_uuid_items')
             ->where(function (QueryExpression $exp) {
                 return $exp->between(
                     'id',
@@ -156,7 +156,7 @@ class ExpressionTypeCastingIntegrationTest extends TestCase
     public function testSelectWithFunction(): void
     {
         $this->_insert();
-        $result = $this->connection->newSelectQuery('id', 'ordered_uuid_items')
+        $result = $this->connection->newSelectQuery(fields: 'id', table: 'ordered_uuid_items')
             ->where(function (QueryExpression $exp, Query $q) {
                 return $exp->eq(
                     'id',

+ 6 - 6
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(['col' => 1]);
+                return $this->connection->newSelectQuery(fields: ['col' => 1]);
             }))
             ->select('col')
             ->from('cte');
@@ -195,7 +195,7 @@ class CommonTableExpressionQueryTest extends TestCase
         );
 
         // test initial state
-        $result = $this->connection->newSelectQuery('*', 'articles')
+        $result = $this->connection->newSelectQuery(fields: '*', table: 'articles')
             ->where(['id' => 4])
             ->execute();
         $this->assertFalse($result->fetch('assoc'));
@@ -213,7 +213,7 @@ class CommonTableExpressionQueryTest extends TestCase
             ->into('articles')
             ->values(
                 $this->connection
-                    ->newSelectQuery('*', 'cte')
+                    ->newSelectQuery(fields: '*', table: 'cte')
             );
 
         $this->assertRegExpSql(
@@ -252,7 +252,7 @@ class CommonTableExpressionQueryTest extends TestCase
             '`INSERT INTO ... WITH` syntax is not supported in SQL Server.'
         );
 
-        $query = $this->connection->newInsertQuery('articles')
+        $query = $this->connection->newInsertQuery(table: 'articles')
             ->insert(['title', 'body'])
             ->values(
                 $this->connection->newSelectQuery()
@@ -285,7 +285,7 @@ class CommonTableExpressionQueryTest extends TestCase
         ];
 
         // test updated state
-        $result = $this->connection->newSelectQuery('*', 'articles')
+        $result = $this->connection->newSelectQuery(fields: '*', table: 'articles')
             ->where(['id' => 4])
             ->execute();
         $this->assertEquals($expected, $result->fetch('assoc'));
@@ -303,7 +303,7 @@ class CommonTableExpressionQueryTest extends TestCase
         );
 
         // test initial state
-        $result = $this->connection->newSelectQuery(['count' => 'COUNT(*)'], 'articles')
+        $result = $this->connection->newSelectQuery(fields: ['count' => 'COUNT(*)'], table: 'articles')
             ->where(['published' => 'Y'])
             ->execute();
         $this->assertEquals(['count' => '3'], $result->fetch('assoc'));

+ 2 - 2
tests/TestCase/Database/QueryTests/TupleComparisonQueryTest.php

@@ -263,8 +263,8 @@ class TupleComparisonQueryTest extends TestCase
                 new TupleComparison(
                     ['articles.id', 'articles.author_id'],
                     $this->connection->newSelectQuery(
-                        ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
-                        ['ArticlesAlias' => 'articles']
+                        fields: ['ArticlesAlias.id', 'ArticlesAlias.author_id'],
+                        table: ['ArticlesAlias' => 'articles']
                     )
                     ->where(['ArticlesAlias.id' => 1]),
                     [],