Skip to content

Commit 6e62900

Browse files
committed
phpunit bumped to 10 and fix in PreparedStatement::getQuery()
1 parent 8a7e211 commit 6e62900

File tree

7 files changed

+31
-35
lines changed

7 files changed

+31
-35
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/vendor
33
/build
44
/.phpunit.result.cache
5+
/.phpunit.cache
56
/.phpdoc
67
/composer.lock
78
/docs

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ $connection = new \sparqlClient\StandardConnection('https://query.wikidata.org/s
5858
// the single `?` is a positional parameter while the `:sf` is a named parameter
5959
$query = $connection->prepare('SELECT * WHERE {?a ? ?c . ?a :sf ?d .} LIMIT 10');
6060
$query->execute([
61-
$factory->namedNode('http://creativecommons.org/ns#license'),
62-
'sf' => $factory->namedNode('http://schema.org/softwareVersion'),
61+
$factory::namedNode('http://creativecommons.org/ns#license'),
62+
'sf' => $factory::namedNode('http://schema.org/softwareVersion'),
6363
]);
6464
foreach ($query as $i) {
6565
print_r($i);
6666
}
6767

6868
// bind a (positional) parameter to a variable
6969
$query = $connection->prepare('SELECT * WHERE {?a ? ?c .} LIMIT 2');
70-
$value = $factory->namedNode('http://creativecommons.org/ns#license');
70+
$value = $factory::namedNode('http://creativecommons.org/ns#license');
7171
$query->bindParam(0, $value);
7272
$query->execute();
7373
foreach ($query as $i) {
7474
print_r($i);
7575
}
76-
$value = $factory->namedNode('http://schema.org/softwareVersion');
76+
$value = $factory::namedNode('http://schema.org/softwareVersion');
7777
$query->execute();
7878
foreach ($query as $i) {
7979
print_r($i);

composer.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@
3131
}
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^9.5",
35-
"phpunit/php-code-coverage": "^9.2",
34+
"phpunit/phpunit": "^10",
3635
"phpstan/phpstan": "*",
37-
"squizlabs/php_codesniffer": "*",
3836
"php-coveralls/php-coveralls": "^2.4",
3937
"http-interop/http-factory-guzzle": "^1.0",
4038
"sweetrdf/quick-rdf": "^1.0.0 | ^2.0.0-RC1"

phpunit.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" verbose="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">src</directory>
6-
</include>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<coverage>
74
<report>
85
<clover outputFile="build/logs/clover.xml"/>
96
</report>
@@ -12,4 +9,9 @@
129
<testsuite name="tests">
1310
<directory>tests</directory>
1411
</testsuite>
12+
<source>
13+
<include>
14+
<directory suffix=".php">src</directory>
15+
</include>
16+
</source>
1517
</phpunit>

src/sparqlClient/PreparedStatement.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,12 @@ private function getQuery(): string {
151151
if (isset($matches[2])) {
152152
$pn = $n;
153153
$from = '?';
154-
$to = $param[$pn] ?? null;
155154
$n++;
156155
} else {
157156
$pn = $matches[1];
158157
$from = ":$pn";
159-
$to = $this->escapeValue($pn);
160158
}
159+
$to = $this->escapeValue($pn);
161160
if ($to === null) {
162161
throw new SparqlException("Parameter $pn value missing");
163162
}

tests/SparqlTest.php

+14-18
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
namespace sparqlClient;
2828

2929
use PDO;
30-
use quickRdf\DataFactory;
30+
use quickRdf\DataFactory as DF;
3131
use rdfInterface\TermInterface;
3232

3333
/**
@@ -38,11 +38,10 @@
3838
class SparqlTest extends \PHPUnit\Framework\TestCase {
3939

4040
public function testSelect(): void {
41-
$df = new DataFactory();
42-
$c = new StandardConnection('https://query.wikidata.org/sparql', $df);
41+
$c = new StandardConnection('https://query.wikidata.org/sparql', new DF());
4342
$query = 'select ?a ?b ?c where {?a ?b ?c} limit 10';
4443

45-
$s = $c->query($query);
44+
$s = $c->query($query);
4645
$d = iterator_to_array($s);
4746
$this->assertCount(10, $d);
4847
foreach ($d as $i) {
@@ -53,28 +52,25 @@ public function testSelect(): void {
5352
}
5453

5554
public function testAsk(): void {
56-
$df = new DataFactory();
57-
$c = new StandardConnection('https://query.wikidata.org/sparql', $df);
55+
$c = new StandardConnection('https://query.wikidata.org/sparql', new DF());
5856
$query = 'ask {<http://foo> <http://bar> <http://baz>}';
5957
$this->assertFalse($c->query($query)->fetchColumn());
6058
}
6159

6260
public function testPrepare(): void {
63-
$df = new DataFactory();
64-
$c = new StandardConnection('https://query.wikidata.org/sparql', $df);
65-
$q = $c->prepare('SELECT * WHERE {?a ? ?c . ?a :sf ?d . ?a ? ?e} LIMIT 1');
61+
$c = new StandardConnection('https://query.wikidata.org/sparql', new DF());
62+
$q = $c->prepare('SELECT * WHERE {?a ? ?c . ?a :sf ?d . ?a ? ?e} LIMIT 1');
6663
$q->execute([
67-
$df->namedNode('http://creativecommons.org/ns#license'),
68-
$df->namedNode('http://schema.org/dateModified'),
69-
'sf' => $df->namedNode('http://schema.org/softwareVersion'),
64+
DF::namedNode('http://creativecommons.org/ns#license'),
65+
DF::namedNode('http://schema.org/dateModified'),
66+
'sf' => DF::namedNode('http://schema.org/softwareVersion'),
7067
]);
71-
$r = $q->fetchAll();
68+
$r = $q->fetchAll();
7269
$this->assertCount(1, $r);
7370
}
7471

7572
public function testExceptions(): void {
76-
$df = new DataFactory();
77-
$c = new StandardConnection('https://query.wikidata.org/sparql', $df);
73+
$c = new StandardConnection('https://query.wikidata.org/sparql', new DF());
7874

7975
$query = 'wrongQuery';
8076
try {
@@ -87,7 +83,7 @@ public function testExceptions(): void {
8783
$query = "";
8884
try {
8985
$q = $c->prepare($query);
90-
$q->execute([$df->literal('foo')]);
86+
$q->execute([DF::literal('foo')]);
9187
} catch (SparqlException $ex) {
9288
$this->assertEquals('Unknown parameter 0', $ex->getMessage());
9389
}
@@ -99,11 +95,11 @@ public function testExceptions(): void {
9995
} catch (SparqlException $ex) {
10096
$this->assertEquals('Parameter 0 value missing', $ex->getMessage());
10197
}
102-
98+
10399
$query = "? :p ";
104100
try {
105101
$q = $c->prepare($query);
106-
$q->execute([$df->literal('foo')]);
102+
$q->execute([DF::literal('foo')]);
107103
} catch (SparqlException $ex) {
108104
$this->assertEquals('Parameter p value missing', $ex->getMessage());
109105
}

tests/StatementTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ private function testWikidata(string $format): void {
9999
$r = $stmt->fetch(PDO::FETCH_OBJ);
100100
$this->assertIsObject($r);
101101
$this->assertCount(3, get_object_vars($r));
102-
$this->assertObjectHasAttribute('a', $r);
103-
$this->assertObjectHasAttribute('b', $r);
104-
$this->assertObjectHasAttribute('c', $r);
102+
$this->assertObjectHasProperty('a', $r);
103+
$this->assertObjectHasProperty('b', $r);
104+
$this->assertObjectHasProperty('c', $r);
105105

106106
$r = $stmt->fetch(PDO::FETCH_COLUMN);
107107
if ($format === 'text/csv') {

0 commit comments

Comments
 (0)