@@ -32,9 +32,9 @@ public function setUp(): void
3232 }
3333 }
3434
35- private function getSubjectUnderTest (): Parser
35+ private function getSubjectUnderTest (string | null $ baseUri ): Parser
3636 {
37- $ subjectUnderTest = new Parser (new DataFactory ());
37+ $ subjectUnderTest = new Parser (new DataFactory (), $ baseUri );
3838 $ subjectUnderTest ->setDirPathForTemporaryFiles (__DIR__ .'/../.cache ' );
3939 return $ subjectUnderTest ;
4040 }
@@ -55,22 +55,41 @@ private function generateTripleStringArray(QuadIteratorInterface $iterator): arr
5555
5656 public function testParseString (): void
5757 {
58- $ iterator = $ this ->getSubjectUnderTest ()->parse ($ this ->testRdfString );
58+ $ iterator = $ this ->getSubjectUnderTest (null )->parse ($ this ->testRdfString );
5959
6060 $ this ->assertEquals (
6161 ['http://bar http://baz 1 ' , 'http://bar http://baz 2 ' ],
6262 $ this ->generateTripleStringArray ($ iterator )
6363 );
6464 }
6565
66+ public function testParseStringWithBaseUri (): void
67+ {
68+ $ str = '@prefix : <http://example.org/prefix/> .
69+ @prefix rdf: <http://example.org/rdf/> .
70+
71+ <name> rdf:type rdf:Property .
72+ :phone rdf:type rdf:Property . ' ;
73+
74+ $ iterator = $ this ->getSubjectUnderTest ('http://test/base/ ' )->parse ($ str );
75+
76+ $ this ->assertEquals (
77+ [
78+ 'http://test/base/name http://example.org/rdf/type http://example.org/rdf/Property ' ,
79+ 'http://example.org/prefix/phone http://example.org/rdf/type http://example.org/rdf/Property ' ,
80+ ],
81+ $ this ->generateTripleStringArray ($ iterator )
82+ );
83+ }
84+
6685 public function testParseResource (): void
6786 {
6887 // put test RDF into a temp. file
6988 $ filepath = tempnam (sys_get_temp_dir (), 'phpunit_parsertest_ ' );
7089 file_put_contents ($ filepath , $ this ->testRdfString );
7190 $ resource = fopen ($ filepath , 'r ' );
7291
73- $ iterator = $ this ->getSubjectUnderTest ()->parse ($ resource );
92+ $ iterator = $ this ->getSubjectUnderTest (null )->parse ($ resource );
7493
7594 $ this ->assertEquals (
7695 ['http://bar http://baz 1 ' , 'http://bar http://baz 2 ' ],
@@ -87,7 +106,7 @@ public function testParseResponseInterface(): void
87106 $ response = $ this ->createMock (ResponseInterface::class);
88107 $ response ->method ('getBody ' )->willReturn ($ stream );
89108
90- $ iterator = $ this ->getSubjectUnderTest ()->parse ($ response );
109+ $ iterator = $ this ->getSubjectUnderTest (null )->parse ($ response );
91110
92111 $ this ->assertEquals (
93112 ['http://bar http://baz 1 ' , 'http://bar http://baz 2 ' ],
@@ -100,7 +119,7 @@ public function testParseStreamInterface(): void
100119 $ stream = $ this ->createMock (StreamInterface::class);
101120 $ stream ->method ('__toString ' )->willReturn ($ this ->testRdfString );
102121
103- $ iterator = $ this ->getSubjectUnderTest ()->parse ($ stream );
122+ $ iterator = $ this ->getSubjectUnderTest (null )->parse ($ stream );
104123
105124 $ this ->assertEquals (
106125 ['http://bar http://baz 1 ' , 'http://bar http://baz 2 ' ],
@@ -110,7 +129,7 @@ public function testParseStreamInterface(): void
110129
111130 public function testParseWithCustomFormat (): void
112131 {
113- $ subjectUnderTest = $ this ->getSubjectUnderTest ();
132+ $ subjectUnderTest = $ this ->getSubjectUnderTest (null );
114133 $ subjectUnderTest ->setFormat ('ntriples ' );
115134 $ iterator = $ subjectUnderTest ->parse ($ this ->testRdfString );
116135
@@ -127,7 +146,7 @@ public function testParseWithInvalidFormat(): void
127146 $ msg .= 'ntriples, n-triples, rdfa, rdfxml, rdfxml-abbrev, rdfxml-xmp, rss-1.0, trig, turtle, text/turtle, ttl, xml ' ;
128147 $ this ->expectExceptionMessage ($ msg );
129148
130- $ subjectUnderTest = $ this ->getSubjectUnderTest ();
149+ $ subjectUnderTest = $ this ->getSubjectUnderTest (null );
131150 $ subjectUnderTest ->setFormat ('invalid ' );
132151 $ subjectUnderTest ->parse ($ this ->testRdfString );
133152 }
@@ -139,7 +158,7 @@ public function testParseStreamResource(): void
139158 file_put_contents ($ filepath , $ this ->testRdfString );
140159 $ resource = fopen ($ filepath , 'r ' );
141160
142- $ iterator = $ this ->getSubjectUnderTest ()->parseStream ($ resource );
161+ $ iterator = $ this ->getSubjectUnderTest (null )->parseStream ($ resource );
143162
144163 $ this ->assertEquals (
145164 ['http://bar http://baz 1 ' , 'http://bar http://baz 2 ' ],
@@ -152,7 +171,7 @@ public function testParseStreamStreamInterface(): void
152171 $ stream = $ this ->createMock (StreamInterface::class);
153172 $ stream ->method ('__toString ' )->willReturn ($ this ->testRdfString );
154173
155- $ iterator = $ this ->getSubjectUnderTest ()->parseStream ($ stream );
174+ $ iterator = $ this ->getSubjectUnderTest (null )->parseStream ($ stream );
156175
157176 $ this ->assertEquals (
158177 ['http://bar http://baz 1 ' , 'http://bar http://baz 2 ' ],
0 commit comments