Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from fusonic/bugfix-chained-where-orderby
Browse files Browse the repository at this point in the history
Bugfix chained where orderby. Fixes #22
  • Loading branch information
davidroth committed Dec 12, 2015
2 parents f28a3ff + aff267b commit 68789c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Fusonic/Linq/Iterator/OrderIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public function orderItems()
$direction = $this->direction;

$itemIterator = $this->iterator;
$itemIterator->rewind();

if($itemIterator instanceof \IteratorAggregate) {
$itemIterator = $itemIterator->getIterator();
$itemIterator->rewind();
}

if (!$itemIterator->valid()) {
$this->orderedIterator = new ArrayIterator();
return;
Expand Down Expand Up @@ -111,4 +116,4 @@ public function orderItems()

$this->orderedIterator = $sorted;
}
}
}
25 changes: 25 additions & 0 deletions tests/Fusonic/Linq/Test/ChainedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

require_once("TestBase.php");

use Fusonic\Linq\Linq;

class ChainedTest extends TestBase
{
public function testWhereOrderBy_returnsFilteredValuesInCorrectOrder()
{
$source = [1, 4, 5, 2, 3];
$result = Linq::from($source)
->where(function($x) {
return $x > 2;
})
->orderBy(function($x) {
return $x;
});

$this->assertEquals([3,4,5], $result->toArray());

// Check multiple evaluations are working as well:
$this->assertEquals([3,4,5], $result->toArray());
}
}

0 comments on commit 68789c2

Please sign in to comment.