-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrated SPARQL Query; addresses SPARQL-issue#1
- Loading branch information
1 parent
0475683
commit 7e1ed8e
Showing
5 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
namespace ProfessionalWiki\SPARQL; | ||
|
||
use MediaWiki\Http\HttpRequestFactory; | ||
|
||
class SparqlLuaQueryRunner { | ||
|
||
public function __construct( | ||
private readonly HttpRequestFactory $requestFactory, | ||
private readonly string $sparqlEndpoint | ||
) { | ||
} | ||
|
||
public function runQuery( string $sparql ): string|null { | ||
$options = [ | ||
'postData' => [ | ||
'query' => $sparql, | ||
'format' => 'json' | ||
], | ||
]; | ||
|
||
return $this->requestFactory->request( 'POST', $this->sparqlEndpoint, $options ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
namespace ProfessionalWiki\SPARQL\Tests; | ||
|
||
use MediaWiki\Http\HttpRequestFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use ProfessionalWiki\SPARQL\SparqlLuaQueryRunner; | ||
|
||
/** | ||
* @covers SparqlLuaQueryRunner::runQuery | ||
*/ | ||
class SparqlLuaQueryRunnerTest extends TestCase { | ||
|
||
public function testRunQuery() { | ||
$SPARQLEndpoint = 'https://www.example.com'; | ||
$httpRequestFactory = $this->createMock( HttpRequestFactory::class ); | ||
$sparqlLua = new SparqlLuaQueryRunner( $httpRequestFactory, $SPARQLEndpoint ); | ||
|
||
$sparql = 'SELECT * WHERE { ?s ?p ?o }'; | ||
$expectedResponse = 'mocking response'; | ||
|
||
$httpRequestFactory | ||
->expects( $this->once() ) | ||
->method( 'request' ) | ||
->with( | ||
'POST', | ||
$SPARQLEndpoint, | ||
[ | ||
'postData' => [ 'query' => $sparql, 'format' => 'json' ] | ||
] | ||
) | ||
->willReturn( $expectedResponse ); | ||
|
||
$response = $sparqlLua->runQuery( $sparql ); | ||
$this->assertSame( $expectedResponse, $response ); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters