Skip to content

Commit

Permalink
Assure various Statement fetch modes are tested on the same response …
Browse files Browse the repository at this point in the history
…body
  • Loading branch information
zozlak committed Dec 8, 2022
1 parent 2ca346c commit 8313930
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 36 deletions.
43 changes: 7 additions & 36 deletions tests/SparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use PDO;
use quickRdf\DataFactory;
use rdfInterface\TermInterface;

/**
* Description of IntegrationTest
Expand All @@ -42,42 +43,12 @@ public function testSelect(): void {
$query = 'select ?a ?b ?c where {?a ?b ?c} limit 10';

$s = $c->query($query);
$d1 = iterator_to_array($s);

$s = $c->query($query);
$d2 = $s->fetchAll();

$s = $c->query($query);
$d3 = [];
while ($row = $s->fetch()) {
$d3[] = $row;
}

$s = $c->query($query);
$c1 = $s->fetchAll(PDO::FETCH_COLUMN);

$s = $c->query($query);
$c2 = [];
while ($col = $s->fetchColumn()) {
$c2[] = $col;
}

$this->assertCount(10, $d1);
$this->assertCount(10, $d2);
$this->assertCount(10, $d3);
$this->assertCount(10, $c1);
$this->assertCount(10, $c2);
for ($i = 0; $i < 10; $i++) {
$this->assertTrue($d1[$i]->a->equals($d2[$i]->a));
$this->assertTrue($d1[$i]->b->equals($d2[$i]->b));
$this->assertTrue($d1[$i]->c->equals($d2[$i]->c));

$this->assertTrue($d1[$i]->a->equals($d3[$i]->a));
$this->assertTrue($d1[$i]->b->equals($d3[$i]->b));
$this->assertTrue($d1[$i]->c->equals($d3[$i]->c));

$this->assertTrue($d1[$i]->a->equals($c1[$i]));
$this->assertTrue($d1[$i]->a->equals($c2[$i]));
$d = iterator_to_array($s);
$this->assertCount(10, $d);
foreach ($d as $i) {
$this->assertInstanceOf(TermInterface::class, $i->a);
$this->assertInstanceOf(TermInterface::class, $i->b);
$this->assertInstanceOf(TermInterface::class, $i->c);
}
}

Expand Down
54 changes: 54 additions & 0 deletions tests/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,58 @@ public function testXmlStar(): void {
$this->assertEquals('bar', $r2['b']->getValue());
$this->assertEquals('https://type', $r2['b']->getDatatype());
}

public function testFetchMode(): void {
$df = new DataFactory();
$c = new StandardConnection('https://query.wikidata.org/sparql', $df);
$query = rawurlencode('select ?a ?b ?c where {?a ?b ?c} limit 10');
$client = new Client();
$request = new Request('GET', 'https://query.wikidata.org/sparql?query=' . $query);
$response = $client->sendRequest($request);
$body = $response->getBody();

$body->seek(0);
$s = new Statement($response, $df);
$d1 = iterator_to_array($s);

$body->seek(0);
$s = new Statement($response, $df);
$d2 = $s->fetchAll();

$body->seek(0);
$s = new Statement($response, $df);
$d3 = [];
while ($row = $s->fetch()) {
$d3[] = $row;
}

$body->seek(0);
$s = new Statement($response, $df);
$c1 = $s->fetchAll(PDO::FETCH_COLUMN);

$body->seek(0);
$s = new Statement($response, $df);
$c2 = [];
while ($col = $s->fetchColumn()) {
$c2[] = $col;
}

$this->assertCount(10, $d1);
$this->assertCount(10, $d2);
$this->assertCount(10, $d3);
$this->assertCount(10, $c1);
$this->assertCount(10, $c2);
for ($i = 0; $i < 10; $i++) {
$this->assertTrue($d1[$i]->a->equals($d2[$i]->a));
$this->assertTrue($d1[$i]->b->equals($d2[$i]->b));
$this->assertTrue($d1[$i]->c->equals($d2[$i]->c));

$this->assertTrue($d1[$i]->a->equals($d3[$i]->a));
$this->assertTrue($d1[$i]->b->equals($d3[$i]->b));
$this->assertTrue($d1[$i]->c->equals($d3[$i]->c));

$this->assertTrue($d1[$i]->a->equals($c1[$i]));
$this->assertTrue($d1[$i]->a->equals($c2[$i]));
}
}
}

0 comments on commit 8313930

Please sign in to comment.