/** * @dataProvider schemes */ public function testThatArrayCompatibleIsUsedForIndexBy(IIteratorScheme $scheme) { $iterator = Traversable::from([1, 2, 3], $scheme)->indexBy(function () { return new \stdClass(); })->getIterator(); $this->assertInstanceOf(get_class($scheme->arrayCompatibleIterator(new \EmptyIterator())), $iterator); }
protected function retrieveValues(\PDOStatement $statement) { $statement->setFetchMode(\PDO::FETCH_ASSOC); switch ($this->retrievalMode) { case Values::AS_ARRAY: return $statement->fetchAll(); case Values::AS_ARRAY_COMPATIBLE_ITERATOR: return new \IteratorIterator($statement); case Values::AS_TRUE_ITERATOR: return new \IteratorIterator($statement); case Values::AS_TRAVERSABLE: return Traversable::from($statement); case Values::AS_COLLECTION: return Collection::from($statement); default: throw new PinqDemoSqlException('Unsupported value retrieval mode'); } }
/** * @dataProvider interpreters */ public function testAliasedTypeHintClass() { $valueSet = [[Traversable::from([])]]; $this->assertRecompilesCorrectly(function (AliasedTraversable $traversable) { return $traversable; }, $valueSet); }
public function testComputesResultsFromUsingMostApplicableParentRequest() { $sourceExpression = $this->queryable->getExpression(); $this->queryResultsCollection->saveResults($sourceExpression, \Pinq\Traversable::from([1])->select(function () { $this->assertTrue(false, 'Source expression results should not be called'); })->getIterator()); $subscopeQueryable = $this->queryable->skip(5); $this->queryResultsCollection->saveResults($subscopeQueryable->getExpression(), [5, 6, 7, 8, 0]); $subSubscopeQueryable = $subscopeQueryable->select(function ($i) { return $i * 10; })->indexBy(function ($i) { return $i / 5; }); $this->assertTrue($this->queryResultsCollection->tryComputeResults($subSubscopeQueryable->getExpression(), $results)); $this->assertInstanceOf(ITraversable::ITRAVERSABLE_TYPE, $results); /** @var $results ITraversable */ $this->assertSame([10 => 50, 12 => 60, 14 => 70, 16 => 80, 0 => 0], $results->asArray()); }
/** * @expectedException \Pinq\PinqException */ public function testCompiledRequestQueryHasherThrowsExceptionForQueryableWithoutDSLProvider() { $hasher = ParameterHasher::compiledRequestQuery(); $hasher->hash((new \Pinq\Providers\Traversable\Provider(Traversable::from([])))->createQueryable()); }