Skip to content
Permalink
Browse files

Added test cases with collections of entities

  • Loading branch information...
davidyell committed Oct 26, 2018
1 parent ea0990a commit 46b3688c3fa8bd4bba39de76d32aafd945e69ea1
Showing with 42 additions and 0 deletions.
  1. +42 −0 tests/TestCase/Collection/CollectionTest.php
@@ -19,6 +19,8 @@
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;
@@ -681,6 +683,26 @@ public function testMaxCallable($items)
}));
}
/**
* 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
*
@@ -693,6 +715,26 @@ public function testMin($items)
$this->assertEquals(['a' => ['b' => ['c' => 4]]], $collection->min('a.b.c'));
}
/**
* 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
*

0 comments on commit 46b3688

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.