Skip to content

Commit 1288611

Browse files
authored
fix sorting flags in CollectionIterator (#2049)
1 parent d92a362 commit 1288611

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Propel/Runtime/Collection/CollectionIterator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function append($value): void
253253
#[\ReturnTypeWillChange]
254254
public function asort(int $flags = SORT_REGULAR): bool
255255
{
256-
parent::asort();
256+
parent::asort($flags);
257257
$this->refreshPositions();
258258

259259
return true;
@@ -267,7 +267,7 @@ public function asort(int $flags = SORT_REGULAR): bool
267267
#[\ReturnTypeWillChange]
268268
public function ksort(int $flags = SORT_REGULAR): bool
269269
{
270-
parent::ksort();
270+
parent::ksort($flags);
271271
$this->refreshPositions();
272272

273273
return true;

tests/Propel/Tests/Runtime/Collection/CollectionIteratorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,22 @@ public function testIsEven()
175175
$this->assertEquals(!(bool)($key % 2), $iterator->isEven(), 'isEven() returns true only when the key is even');
176176
}
177177
}
178+
179+
/**
180+
* @return void
181+
*/
182+
public function testSortingUsesFlags()
183+
{
184+
$data = ['img10', 'img2'];
185+
$collection = new Collection($data);
186+
$iterator = new CollectionIterator($collection);
187+
$iterator->asort(SORT_NATURAL);
188+
$this->assertSame(['img2', 'img10'], array_values($iterator->getArrayCopy()), 'asort() should respect sorting flags');
189+
190+
$assoc = ['b10' => 'foo', 'b2' => 'bar'];
191+
$collection = new Collection($assoc);
192+
$iterator = new CollectionIterator($collection);
193+
$iterator->ksort(SORT_NATURAL);
194+
$this->assertSame(['b2', 'b10'], array_keys($iterator->getArrayCopy()), 'ksort() should respect sorting flags');
195+
}
178196
}

0 commit comments

Comments
 (0)