@@ -77,6 +77,29 @@ public function testSortDescendingByValue(iterable $elements, iterable $expected
7777 self ::assertSame ($ expected , $ actual ->toArray ());
7878 }
7979
80+ public function testSortDescendingByValueWithPredicate (): void
81+ {
82+ /** @Given a collection with unordered Amount objects */
83+ $ collection = Collection::createFrom (elements: [
84+ new Amount (value: 100.50 , currency: Currency::USD ),
85+ new Amount (value: 150.75 , currency: Currency::EUR ),
86+ new Amount (value: 200.00 , currency: Currency::USD )
87+ ]);
88+
89+ /** @When sorting the collection in descending order by value with a custom predicate */
90+ $ actual = $ collection ->sort (
91+ order: Order::DESCENDING_VALUE ,
92+ predicate: static fn (Amount $ first , Amount $ second ): int => $ first ->value <=> $ second ->value
93+ );
94+
95+ /** @Then the collection should be sorted by value in descending order */
96+ self ::assertSame ([
97+ 2 => ['value ' => 200.00 , 'currency ' => Currency::USD ->name ],
98+ 1 => ['value ' => 150.75 , 'currency ' => Currency::EUR ->name ],
99+ 0 => ['value ' => 100.50 , 'currency ' => Currency::USD ->name ]
100+ ], $ actual ->toArray ());
101+ }
102+
80103 public static function ascendingKeySortDataProvider (): iterable
81104 {
82105 yield 'Floats ascending by key ' => [
0 commit comments