Skip to content

Commit

Permalink
embeddables: add order by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Mar 11, 2021
1 parent ab9cdcf commit 1c9a840
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/cases/integration/Collection/collection.embeddables.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace NextrasTests\Orm\Integration\Collection;


use Nextras\Orm\Collection\Functions\MaxAggregateFunction;
use Nextras\Orm\Collection\Functions\MinAggregateFunction;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Exception\InvalidArgumentException;
use NextrasTests\Orm\Currency;
use NextrasTests\Orm\DataTestCase;
Expand Down Expand Up @@ -36,6 +39,33 @@ class CollectionEmbeddablesTest extends DataTestCase
}


public function testOrderBy()
{
$books = $this->orm->books->findAll()->orderBy('price->cents');
$bookIds = $books->fetchPairs(null, 'id');
Assert::same([3, 1, 2, 4], $bookIds);

$author = $this->orm->authors->getByIdChecked(1);
$books = $author->books->toCollection()->orderBy('price->cents', ICollection::DESC);
$bookIds = $books->fetchPairs(null, 'id');
Assert::same([2, 1], $bookIds);

$authors = $this->orm->authors->findAll()->orderBy([
MaxAggregateFunction::class,
'books->price->cents',
]);
$authorIds = $authors->fetchPairs(null, 'id');
Assert::same([1, 2], $authorIds);

$authors = $this->orm->authors->findAll()->orderBy([
MinAggregateFunction::class,
'books->price->cents',
]);
$authorIds = $authors->fetchPairs(null, 'id');
Assert::same([2, 1], $authorIds);
}


public function testInvalidExpression(): void
{
Assert::throws(function (): void {
Expand Down

0 comments on commit 1c9a840

Please sign in to comment.