Browse Source

Merge branch '4.next' into http-client-mock

Mark Story 4 years ago
parent
commit
7661311089

+ 0 - 1
.github/workflows/ci.yml

@@ -124,7 +124,6 @@ jobs:
         else
           vendor/bin/phpunit
         fi
-      continue-on-error: ${{ matrix.php-version == '8.1' }}
 
     - name: Submit code coverage
       if: matrix.php-version == '8.0'

+ 6 - 6
src/Database/Query.php

@@ -1523,13 +1523,13 @@ class Query implements ExpressionInterface, IteratorAggregate
      * $query->limit($query->newExpr()->add(['1 + 1'])); // LIMIT (1 + 1)
      * ```
      *
-     * @param \Cake\Database\ExpressionInterface|int|null $num number of records to be returned
+     * @param \Cake\Database\ExpressionInterface|int|null $limit number of records to be returned
      * @return $this
      */
-    public function limit($num)
+    public function limit($limit)
     {
         $this->_dirty();
-        $this->_parts['limit'] = $num;
+        $this->_parts['limit'] = $limit;
 
         return $this;
     }
@@ -1549,13 +1549,13 @@ class Query implements ExpressionInterface, IteratorAggregate
      * $query->offset($query->newExpr()->add(['1 + 1'])); // OFFSET (1 + 1)
      * ```
      *
-     * @param \Cake\Database\ExpressionInterface|int|null $num number of records to be skipped
+     * @param \Cake\Database\ExpressionInterface|int|null $offset number of records to be skipped
      * @return $this
      */
-    public function offset($num)
+    public function offset($offset)
     {
         $this->_dirty();
-        $this->_parts['offset'] = $num;
+        $this->_parts['offset'] = $offset;
 
         return $this;
     }

+ 4 - 4
src/Datasource/QueryInterface.php

@@ -172,10 +172,10 @@ interface QueryInterface
      * $query->limit($query->newExpr()->add(['1 + 1'])); // LIMIT (1 + 1)
      * ```
      *
-     * @param \Cake\Database\ExpressionInterface|int|null $num number of records to be returned
+     * @param \Cake\Database\ExpressionInterface|int|null $limit number of records to be returned
      * @return $this
      */
-    public function limit($num);
+    public function limit($limit);
 
     /**
      * Sets the number of records that should be skipped from the original result set
@@ -192,10 +192,10 @@ interface QueryInterface
      *  $query->offset($query->newExpr()->add(['1 + 1'])); // OFFSET (1 + 1)
      * ```
      *
-     * @param \Cake\Database\ExpressionInterface|int|null $num number of records to be skipped
+     * @param \Cake\Database\ExpressionInterface|int|null $offset number of records to be skipped
      * @return $this
      */
-    public function offset($num);
+    public function offset($offset);
 
     /**
      * Adds a single or multiple fields to be used in the ORDER clause for this query.

+ 4 - 3
src/ORM/Query.php

@@ -1215,6 +1215,10 @@ class Query extends DatabaseQuery implements JsonSerializable, QueryInterface
         $types = [];
 
         foreach ($select as $alias => $value) {
+            if ($value instanceof TypedResultInterface) {
+                $types[$alias] = $value->getReturnType();
+                continue;
+            }
             if (isset($typeMap[$alias])) {
                 $types[$alias] = $typeMap[$alias];
                 continue;
@@ -1222,9 +1226,6 @@ class Query extends DatabaseQuery implements JsonSerializable, QueryInterface
             if (is_string($value) && isset($typeMap[$value])) {
                 $types[$alias] = $typeMap[$value];
             }
-            if ($value instanceof TypedResultInterface) {
-                $types[$alias] = $value->getReturnType();
-            }
         }
         $this->getSelectTypeMap()->addDefaults($types);
     }

+ 2 - 0
tests/TestCase/Filesystem/FilesystemTest.php

@@ -37,6 +37,8 @@ class FilesystemTest extends TestCase
     {
         parent::setUp();
 
+        $this->skipIf(version_compare(PHP_VERSION, '8.1.0-dev', '>='));
+
         $this->vfs = vfsStream::setup('root');
         $this->vfsPath = vfsStream::url('root');
 

+ 23 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -1199,6 +1199,29 @@ class QueryRegressionTest extends TestCase
     }
 
     /**
+     * Test that the type specified in function expressions takes priority over
+     * default types set for columns.
+     *
+     * @see https://github.com/cakephp/cakephp/issues/13049
+     * @return void
+     */
+    public function testTypemapInFunctions3(): void
+    {
+        $this->loadFixtures('Comments');
+        $table = $this->getTableLocator()->get('Comments');
+        $query = $table->find();
+
+        $result = $query->select(['id' => $query->func()->min('id')])
+            ->first();
+        $this->assertSame(1.0, $result['id']);
+
+        $query = $table->find();
+        $result = $query->select(['id' => $query->func()->min('id', ['boolean'])])
+            ->first();
+        $this->assertTrue($result['id']);
+    }
+
+    /**
      * Test that contain queries map types correctly.
      */
     public function testBooleanConditionsInContain(): void