/** * @dataProvider oneToTen */ public function testThatClearRemovesAllScopedItems(\Pinq\ICollection $collection, array $data) { $collection->where(function ($i) { return $i <= 5; })->clear(); $this->assertMatches($collection, [5 => 6, 6 => 7, 7 => 8, 8 => 9, 9 => 10]); }
/** * @dataProvider oneToTen */ public function testThatCollectionApplyWorksOnScopedValues(\Pinq\ICollection $collection, array $data) { $collection->where(function ($i) { return $i % 2 === 0; })->apply(function (&$i) { $i *= 10; }); $this->assertMatches($collection, [1, 20, 3, 40, 5, 60, 7, 80, 9, 100]); }
/** * @dataProvider oneToTen */ public function testThatQueryUpdatesWhenSourceCollectionIsMutated(\Pinq\ICollection $collection, array $data) { $query = $collection->where(function ($i) { return $i % 2 === 0; })->orderByDescending(function ($i) { return $i; })->groupJoin(range(1, 10, 2))->on(function ($i, $v) { return $v < $i; })->to(function ($i, \Pinq\ITraversable $nums) { return $i . ':' . $nums->implode(','); }); $this->assertMatchesValues($query, ['10:1,3,5,7,9', '8:1,3,5,7', '6:1,3,5', '4:1,3', '2:1']); $collection->removeRange([4, 5]); unset($collection[7]); $this->assertMatchesValues($query, ['10:1,3,5,7,9', '6:1,3,5', '2:1']); }