/** * @dataProvider oneToTen */ public function testThatQueryUpdatesWhenValuesAreMutated(\Pinq\ITraversable $traversable, array $data) { $mutableValues = new \ArrayObject([2, 4, 6, 8, 10]); $query = $traversable->whereIn($mutableValues)->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']); $mutableValues->exchangeArray([1, 3, 5, 7, 9]); $this->assertMatchesValues($query, ['9:1,3,5,7', '7:1,3,5', '5:1,3', '3:1', '1:']); }
public function visitOperation(Segments\Operation $query) { $otherValues = self::evaluateSource($query->getSource(), $this->resolvedParameters); switch ($query->getOperationType()) { case Segments\Operation::UNION: $this->traversable = $this->traversable->union($otherValues); break; case Segments\Operation::INTERSECT: $this->traversable = $this->traversable->intersect($otherValues); break; case Segments\Operation::DIFFERENCE: $this->traversable = $this->traversable->difference($otherValues); break; case Segments\Operation::APPEND: $this->traversable = $this->traversable->append($otherValues); break; case Segments\Operation::WHERE_IN: $this->traversable = $this->traversable->whereIn($otherValues); break; case Segments\Operation::EXCEPT: $this->traversable = $this->traversable->except($otherValues); break; } }
/** * @dataProvider oneToTen */ public function testThatWhereInWithDuplicateValuesPreservesTheOriginalKeys(\Pinq\ITraversable $traversable, array $data) { $otherData = ['test' => 1, 'anotherkey' => 3, 1000 => 5]; $values = $traversable->whereIn($otherData); $this->assertMatches($values, array_intersect($data, $otherData)); }