Browse Source

Fix tests errors.

ADmad 3 years ago
parent
commit
4a85c82cee

+ 4 - 4
tests/TestCase/Database/QueryTest.php

@@ -3593,8 +3593,8 @@ class QueryTest extends TestCase
         $this->assertSame(1, $bindings[1]['value']);
         $this->assertSame('integer', $bindings[1]['type']);
 
-        $this->assertSame('1', $result['id']);
-        $this->assertSame('1', $result['user_id']);
+        $this->assertSame(1, (int)$result['id']);
+        $this->assertSame(1, (int)$result['user_id']);
     }
 
     /**
@@ -3632,8 +3632,8 @@ class QueryTest extends TestCase
         $this->assertSame(1, $bindings[1]['value']);
         $this->assertNull($bindings[1]['type']);
 
-        $this->assertSame('1', $result['id']);
-        $this->assertSame('1', $result['user_id']);
+        $this->assertSame(1, (int)$result['id']);
+        $this->assertSame(1, (int)$result['user_id']);
     }
 
     /**

+ 30 - 19
tests/TestCase/Database/QueryTests/CaseExpressionQueryTest.php

@@ -99,6 +99,10 @@ class CaseExpressionQueryTest extends TestCase
 
     public function testSearchedCase(): void
     {
+        $typeMap = new TypeMap([
+            'price' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(function (Query $query) {
                 return [
@@ -115,22 +119,23 @@ class CaseExpressionQueryTest extends TestCase
             })
             ->from('products')
             ->orderAsc('price')
-            ->orderAsc('name');
+            ->orderAsc('name')
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
                 'name' => 'First product',
-                'price' => '10',
+                'price' => 10,
                 'price_range' => 'Under $20',
             ],
             [
                 'name' => 'Second product',
-                'price' => '20',
+                'price' => 20,
                 'price_range' => 'Under $30',
             ],
             [
                 'name' => 'Third product',
-                'price' => '30',
+                'price' => 30,
                 'price_range' => '$30 and above',
             ],
         ];
@@ -139,6 +144,11 @@ class CaseExpressionQueryTest extends TestCase
 
     public function testOrderByCase(): void
     {
+        $typeMap = new TypeMap([
+            'article_id' => 'integer',
+            'user_id' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(['article_id', 'user_id'])
             ->from('comments')
@@ -154,32 +164,33 @@ class CaseExpressionQueryTest extends TestCase
                     ->case($query->identifier('comments.article_id'))
                     ->when(2)
                     ->then($query->identifier('comments.user_id'));
-            });
+            })
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
-                'article_id' => '1',
-                'user_id' => '4',
+                'article_id' => 1,
+                'user_id' => 4,
             ],
             [
-                'article_id' => '1',
-                'user_id' => '2',
+                'article_id' => 1,
+                'user_id' => 2,
             ],
             [
-                'article_id' => '1',
-                'user_id' => '1',
+                'article_id' => 1,
+                'user_id' => 1,
             ],
             [
-                'article_id' => '1',
-                'user_id' => '1',
+                'article_id' => 1,
+                'user_id' => 1,
             ],
             [
-                'article_id' => '2',
-                'user_id' => '1',
+                'article_id' => 2,
+                'user_id' => 1,
             ],
             [
-                'article_id' => '2',
-                'user_id' => '2',
+                'article_id' => 2,
+                'user_id' => 2,
             ],
         ];
         $this->assertSame($expected, $query->execute()->fetchAll(StatementInterface::FETCH_TYPE_ASSOC));
@@ -248,10 +259,10 @@ class CaseExpressionQueryTest extends TestCase
             ->from('comments')
             ->where(['comments.published' => 'Y']);
 
-        $this->assertSame('1', $query->execute()->fetch()[0]);
+        $this->assertSame(1, (int)$query->execute()->fetch()[0]);
 
         $query->where(['comments.published' => 'N'], [], true);
-        $this->assertSame('5', $query->execute()->fetch()[0]);
+        $this->assertSame(5, (int)$query->execute()->fetch()[0]);
     }
 
     public function testInferredReturnType(): void

+ 50 - 19
tests/TestCase/Database/QueryTests/TupleComparisonQueryTest.php

@@ -24,6 +24,7 @@ use Cake\Database\Driver\Sqlserver;
 use Cake\Database\Expression\TupleComparison;
 use Cake\Database\Query;
 use Cake\Database\StatementInterface;
+use Cake\Database\TypeMap;
 use Cake\Datasource\ConnectionManager;
 use Cake\TestSuite\TestCase;
 use PDOException;
@@ -108,6 +109,11 @@ class TupleComparisonQueryTest extends TestCase
 
     public function testInWithMultiResultSubquery(): void
     {
+        $typeMap = new TypeMap([
+            'id' => 'integer',
+            'author_id' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(['articles.id', 'articles.author_id'])
             ->from('articles')
@@ -122,16 +128,17 @@ class TupleComparisonQueryTest extends TestCase
                     'IN'
                 ),
             ])
-            ->orderAsc('articles.id');
+            ->orderAsc('articles.id')
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
-                'id' => '1',
-                'author_id' => '1',
+                'id' => 1,
+                'author_id' => 1,
             ],
             [
-                'id' => '3',
-                'author_id' => '1',
+                'id' => 3,
+                'author_id' => 1,
             ],
         ];
         $this->assertSame($expected, $query->execute()->fetchAll(StatementInterface::FETCH_TYPE_ASSOC));
@@ -139,6 +146,11 @@ class TupleComparisonQueryTest extends TestCase
 
     public function testInWithSingleResultSubquery(): void
     {
+        $typeMap = new TypeMap([
+            'id' => 'integer',
+            'author_id' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(['articles.id', 'articles.author_id'])
             ->from('articles')
@@ -152,12 +164,13 @@ class TupleComparisonQueryTest extends TestCase
                     [],
                     'IN'
                 ),
-            ]);
+            ])
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
-                'id' => '1',
-                'author_id' => '1',
+                'id' => 1,
+                'author_id' => 1,
             ],
         ];
         $this->assertSame($expected, $query->execute()->fetchAll(StatementInterface::FETCH_TYPE_ASSOC));
@@ -165,6 +178,11 @@ class TupleComparisonQueryTest extends TestCase
 
     public function testInWithMultiArrayValues(): void
     {
+        $typeMap = new TypeMap([
+            'id' => 'integer',
+            'author_id' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(['articles.id', 'articles.author_id'])
             ->from('articles')
@@ -176,16 +194,17 @@ class TupleComparisonQueryTest extends TestCase
                     'IN'
                 ),
             ])
-            ->orderAsc('articles.id');
+            ->orderAsc('articles.id')
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
-                'id' => '1',
-                'author_id' => '1',
+                'id' => 1,
+                'author_id' => 1,
             ],
             [
-                'id' => '3',
-                'author_id' => '1',
+                'id' => 3,
+                'author_id' => 1,
             ],
         ];
         $this->assertSame($expected, $query->execute()->fetchAll(StatementInterface::FETCH_TYPE_ASSOC));
@@ -228,6 +247,11 @@ class TupleComparisonQueryTest extends TestCase
 
     public function testEqualWithSingleResultSubquery(): void
     {
+        $typeMap = new TypeMap([
+            'id' => 'integer',
+            'author_id' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(['articles.id', 'articles.author_id'])
             ->from('articles')
@@ -241,12 +265,13 @@ class TupleComparisonQueryTest extends TestCase
                     [],
                     '='
                 ),
-            ]);
+            ])
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
-                'id' => '1',
-                'author_id' => '1',
+                'id' => 1,
+                'author_id' => 1,
             ],
         ];
         $this->assertSame($expected, $query->execute()->fetchAll(StatementInterface::FETCH_TYPE_ASSOC));
@@ -254,6 +279,11 @@ class TupleComparisonQueryTest extends TestCase
 
     public function testEqualWithSingleArrayValue(): void
     {
+        $typeMap = new TypeMap([
+            'id' => 'integer',
+            'author_id' => 'integer',
+        ]);
+
         $query = $this->query
             ->select(['articles.id', 'articles.author_id'])
             ->from('articles')
@@ -265,12 +295,13 @@ class TupleComparisonQueryTest extends TestCase
                     '='
                 ),
             ])
-            ->orderAsc('articles.id');
+            ->orderAsc('articles.id')
+            ->setSelectTypeMap($typeMap);
 
         $expected = [
             [
-                'id' => '1',
-                'author_id' => '1',
+                'id' => 1,
+                'author_id' => 1,
             ],
         ];
         $this->assertSame($expected, $query->execute()->fetchAll(StatementInterface::FETCH_TYPE_ASSOC));