Skip to content

Commit da70a10

Browse files
committed
Fix Stream::sotBy method working with float values
1 parent 4b221ce commit da70a10

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/WS/Utils/Collections/SerialStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function sortBy(callable $extractor): Stream
137137
sort($values);
138138
$newList = $this->emptyList();
139139
foreach ($values as $value) {
140-
$els = $map[$value] ?? [];
140+
$els = $map[$value.''] ?? [];
141141
$newList->addAll($els);
142142
}
143143
$this->list = $newList;

tests/WS/Utils/Collections/SerialStreamTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Exception;
99
use PHPUnit\Framework\TestCase;
1010
use WS\Utils\Collections\UnitConstraints\CollectionIsEqual;
11+
use WS\Utils\Collections\Utils\ExampleObject;
1112
use WS\Utils\Collections\Utils\InvokeCounter;
1213
use WS\Utils\Collections\Utils\TestInteger;
1314

@@ -502,6 +503,23 @@ public function sortingWithNotScalarValue(): void
502503
;
503504
}
504505

506+
/**
507+
* @test
508+
*/
509+
public function sortingWithSingleValue(): void
510+
{
511+
$obj = new ExampleObject();
512+
$obj->property = 1.12;
513+
$sortedFirstElement = $this->createCollection([$obj])
514+
->stream()
515+
->sortBy(static function (ExampleObject $object) {
516+
return $object->property;
517+
})
518+
->findFirst()
519+
;
520+
self::assertNotNull($sortedFirstElement);
521+
}
522+
505523
/**
506524
* @dataProvider sortCases
507525
* @test

0 commit comments

Comments
 (0)