Browse Source

Added test cases with collections of entities

David Yell 7 years ago
parent
commit
46b3688c3f
1 changed files with 42 additions and 0 deletions
  1. 42 0
      tests/TestCase/Collection/CollectionTest.php

+ 42 - 0
tests/TestCase/Collection/CollectionTest.php

@@ -19,6 +19,8 @@ use ArrayObject;
 use Cake\Collection\Collection;
 use Cake\Collection\CollectionInterface;
 use Cake\Collection\CollectionTrait;
+use Cake\ORM\Entity;
+use Cake\ORM\ResultSet;
 use Cake\TestSuite\TestCase;
 use NoRewindIterator;
 
@@ -682,6 +684,26 @@ class CollectionTest extends TestCase
     }
 
     /**
+     * Test max with a collection of Entities
+     *
+     * @return void
+     */
+    public function testMaxWithEntities()
+    {
+        $collection = new Collection([
+            new Entity(['id' => 1, 'count' => 18]),
+            new Entity(['id' => 2, 'count' => 9]),
+            new Entity(['id' => 3, 'count' => 42]),
+            new Entity(['id' => 4, 'count' => 4]),
+            new Entity(['id' => 5, 'count' => 22])
+        ]);
+
+        $expected = new Entity(['id' => 3, 'count' => 42]);
+
+        $this->assertEquals($expected, $collection->max('count'));
+    }
+
+    /**
      * Tests min
      *
      * @dataProvider sortProvider
@@ -694,6 +716,26 @@ class CollectionTest extends TestCase
     }
 
     /**
+     * Test min with a collection of Entities
+     *
+     * @return void
+     */
+    public function testMinWithEntities()
+    {
+        $collection = new Collection([
+            new Entity(['id' => 1, 'count' => 18]),
+            new Entity(['id' => 2, 'count' => 9]),
+            new Entity(['id' => 3, 'count' => 42]),
+            new Entity(['id' => 4, 'count' => 4]),
+            new Entity(['id' => 5, 'count' => 22])
+        ]);
+
+        $expected = new Entity(['id' => 4, 'count' => 4]);
+
+        $this->assertEquals($expected, $collection->min('count'));
+    }
+
+    /**
      * Provider for some groupBy tests
      *
      * @return array