Skip to content

Commit

Permalink
Added test cases with collections of entities
Browse files Browse the repository at this point in the history
  • Loading branch information
David Yell committed Oct 26, 2018
1 parent ea0990a commit 46b3688
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/TestCase/Collection/CollectionTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down

0 comments on commit 46b3688

Please sign in to comment.