Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit dcdac89

Browse files
PHP 8.1 compatibility
1 parent 1a4c6fb commit dcdac89

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

composer.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"keywords": ["task-runner"],
55
"type": "robo-tasks",
66
"require": {
7-
"php": "~7.1",
8-
"consolidation/robo": "^1 || ^2"
7+
"php": ">=7.4",
8+
"consolidation/robo": "^3.0"
99
},
1010
"require-dev": {
11-
"easyrdf/easyrdf": "dev-master",
11+
"easyrdf/easyrdf": "^1.1",
1212
"phpunit/phpunit": "~7 || ~8 || ~9",
1313
"slevomat/coding-standard": "~6",
1414
"squizlabs/php_codesniffer": "~3"
@@ -31,7 +31,11 @@
3131
}
3232
},
3333
"config": {
34-
"sort-packages": true
34+
"sort-packages": true,
35+
"allow-plugins": {
36+
"cweagans/composer-patches": true,
37+
"dealerdirect/phpcodesniffer-composer-installer": true
38+
}
3539
},
3640
"minimum-stability": "dev",
3741
"prefer-stable": true

src/Tasks/Sparql/AbstractImport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class AbstractImport extends BaseTask
1818
*
1919
* @var array
2020
*/
21-
protected $stack = [];
21+
protected array $stack = [];
2222

2323
/**
2424
* {@inheritdoc}

src/Tasks/Sparql/Query.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class Query extends BaseTask
2020
*
2121
* @var array
2222
*/
23-
protected $stack = [];
23+
protected array $stack = [];
2424

2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function run()
28+
public function run(): Result
2929
{
3030
if (empty($this->endpointUrl)) {
3131
return Result::error($this, "Endpoint URL not set");

src/Tasks/Sparql/SparqlTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait SparqlTrait
1414
*
1515
* @var string
1616
*/
17-
protected $endpointUrl;
17+
protected string $endpointUrl;
1818

1919
/**
2020
* Sets the SPARQL endpoint.

src/Tasks/Sparql/loadTasks.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Robo\Sparql\Tasks\Sparql;
66

7+
use Robo\Collection\CollectionBuilder;
8+
79
/**
810
* Provides loaders for SPARQL Robo tasks.
911
*/
@@ -15,7 +17,7 @@ trait loadTasks
1517
* @return \Robo\Sparql\Tasks\Sparql\Query|\Robo\Collection\CollectionBuilder
1618
* The task object.
1719
*/
18-
public function taskSparqlQuery()
20+
public function taskSparqlQuery(): CollectionBuilder
1921
{
2022
return $this->task(Query::class);
2123
}
@@ -26,7 +28,7 @@ public function taskSparqlQuery()
2628
* @return \Robo\Sparql\Tasks\Sparql\ImportFromString|\Robo\Collection\CollectionBuilder
2729
* The task object.
2830
*/
29-
public function taskSparqlImportFromString()
31+
public function taskSparqlImportFromString(): CollectionBuilder
3032
{
3133
return $this->task(ImportFromString::class);
3234
}

tests/src/SparqlRoboTasksTest.php

+20-32
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44

55
namespace Robo\Sparql\Tests;
66

7-
use League\Container\ContainerAwareTrait;
7+
use EasyRdf\Sparql\Client;
88
use PHPUnit\Framework\TestCase;
99
use Robo\Collection\CollectionBuilder;
10+
use Robo\Common\BuilderAwareTrait;
11+
use Robo\Contract\BuilderAwareInterface;
1012
use Robo\Robo;
1113
use Robo\Sparql\Tasks\Sparql\loadTasks;
1214
use Robo\TaskAccessor;
13-
use Symfony\Component\Console\Output\NullOutput;
1415

15-
class SparqlRoboTasksTest extends TestCase
16+
class SparqlRoboTasksTest extends TestCase implements BuilderAwareInterface
1617
{
18+
use BuilderAwareTrait;
1719
use loadTasks;
18-
use ContainerAwareTrait;
1920
use TaskAccessor;
2021

2122
/**
@@ -24,19 +25,8 @@ class SparqlRoboTasksTest extends TestCase
2425
protected function setUp(): void
2526
{
2627
parent::setUp();
27-
$container = Robo::createDefaultContainer(null, new NullOutput());
28-
$this->setContainer($container);
29-
}
30-
31-
/**
32-
* Scaffold the collection builder.
33-
*
34-
* @return \Robo\Collection\CollectionBuilder
35-
*/
36-
public function collectionBuilder(): CollectionBuilder
37-
{
38-
$emptyRobofile = new \Robo\Tasks();
39-
return $this->getContainer()->get('collectionBuilder', [$emptyRobofile]);
28+
$builder = CollectionBuilder::create(Robo::createContainer(), $this);
29+
$this->setBuilder($builder);
4030
}
4131

4232
/**
@@ -78,23 +68,21 @@ public function testImport(string $method, string $triples1, string $triples2):
7868
->addTriples('http://example.com/graph2', $triples2)
7969
->run();
8070

81-
$result = $this->taskSparqlQuery()
82-
->setEndpointUrl($this->getSparqlEndpoint() . '/sparql')
83-
->addQuery('SELECT ?subject ?predicate ?object WHERE { GRAPH <http://example.com/graph1> { ?subject ?predicate ?object } }')
84-
->addQuery('SELECT ?subject ?predicate ?object WHERE { GRAPH <http://example.com/graph2> { ?subject ?predicate ?object } }')
85-
->addQuery('CLEAR GRAPH <http://example.com/graph1>')
86-
->addQuery('CLEAR GRAPH <http://example.com/graph2>')
87-
->run();
71+
$client = new Client($this->getSparqlEndpoint() . '/sparql');
8872

89-
/** @var \EasyRdf\Sparql\Result[] $results */
90-
$results = $result->getData()['results'];
73+
$results = $client->query('SELECT ?subject ?predicate ?object WHERE { GRAPH <http://example.com/graph1> { ?subject ?predicate ?object } }');
74+
$this->assertSame('http://example.com/subject1', $results[0]->subject->getUri());
75+
$this->assertSame('http://example.com/predicate', $results[0]->predicate->getUri());
76+
$this->assertSame('test 1', $results[0]->object->getValue());
9177

92-
$this->assertSame('http://example.com/subject1', $results[0][0]->subject->getUri());
93-
$this->assertSame('http://example.com/predicate', $results[0][0]->predicate->getUri());
94-
$this->assertSame('test 1', $results[0][0]->object->getValue());
95-
$this->assertSame('http://example.com/subject2', $results[1][0]->subject->getUri());
96-
$this->assertSame('http://example.com/predicate', $results[1][0]->predicate->getUri());
97-
$this->assertSame('test 2', $results[1][0]->object->getValue());
78+
$results = $client->query('SELECT ?subject ?predicate ?object WHERE { GRAPH <http://example.com/graph2> { ?subject ?predicate ?object } }');
79+
$this->assertSame('http://example.com/subject2', $results[0]->subject->getUri());
80+
$this->assertSame('http://example.com/predicate', $results[0]->predicate->getUri());
81+
$this->assertSame('test 2', $results[0]->object->getValue());
82+
83+
// Cleanup.
84+
$client->query('CLEAR GRAPH <http://example.com/graph1>');
85+
$client->query('CLEAR GRAPH <http://example.com/graph2>');
9886
}
9987

10088
/**

0 commit comments

Comments
 (0)