diff --git a/tests/cases/integration/Collection/collection.embeddables.phpt b/tests/cases/integration/Collection/collection.embeddables.phpt index 0d4f0261..4af110d6 100644 --- a/tests/cases/integration/Collection/collection.embeddables.phpt +++ b/tests/cases/integration/Collection/collection.embeddables.phpt @@ -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; @@ -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 {