4
4
5
5
namespace Robo \Sparql \Tests ;
6
6
7
- use League \ Container \ ContainerAwareTrait ;
7
+ use EasyRdf \ Sparql \ Client ;
8
8
use PHPUnit \Framework \TestCase ;
9
9
use Robo \Collection \CollectionBuilder ;
10
+ use Robo \Common \BuilderAwareTrait ;
11
+ use Robo \Contract \BuilderAwareInterface ;
10
12
use Robo \Robo ;
11
13
use Robo \Sparql \Tasks \Sparql \loadTasks ;
12
14
use Robo \TaskAccessor ;
13
- use Symfony \Component \Console \Output \NullOutput ;
14
15
15
- class SparqlRoboTasksTest extends TestCase
16
+ class SparqlRoboTasksTest extends TestCase implements BuilderAwareInterface
16
17
{
18
+ use BuilderAwareTrait;
17
19
use loadTasks;
18
- use ContainerAwareTrait;
19
20
use TaskAccessor;
20
21
21
22
/**
@@ -24,19 +25,8 @@ class SparqlRoboTasksTest extends TestCase
24
25
protected function setUp (): void
25
26
{
26
27
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 );
40
30
}
41
31
42
32
/**
@@ -78,23 +68,21 @@ public function testImport(string $method, string $triples1, string $triples2):
78
68
->addTriples ('http://example.com/graph2 ' , $ triples2 )
79
69
->run ();
80
70
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 ' );
88
72
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 ());
91
77
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> ' );
98
86
}
99
87
100
88
/**
0 commit comments