|
|
@@ -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
|