Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor CS tweaks in SparqlLuaQueryRunnerIntegrationTest #12

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions tests/integration/SparqlLuaQueryRunnerIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,30 @@
use ProfessionalWiki\SPARQL\SparqlLuaQueryRunner;

/**
* @covers SparqlLuaQueryRunner
* @covers \ProfessionalWiki\SPARQL\SparqlLuaQueryRunner
*/
class SparqlLuaQueryRunnerIntegrationTest extends TestCase {

private SparqlLuaQueryRunner $queryRunner;

protected function setUp(): void {
private function newQueryRunner(): SparqlLuaQueryRunner {
$sparqlEndpoint = MediaWikiServices::getInstance()->getMainConfig()->get( 'SPARQLEndpoint' );

if ( !is_string( $sparqlEndpoint ) ) {
$this->markTestSkipped( 'Missing required config variable SPARQLEndpoint' );
}

$requestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory();
$this->queryRunner = new SparqlLuaQueryRunner( $requestFactory, $sparqlEndpoint );
return new SparqlLuaQueryRunner( $requestFactory, $sparqlEndpoint );
}

public function testRunQueryWhenSparqlQueryIsEmpty(): void {
$sparqlQuery = '';
$result = $this->queryRunner->runQuery( $sparqlQuery );
$result = $this->newQueryRunner()->runQuery( $sparqlQuery );
$this->assertNull( $result );
}

public function testRunQueryReturnsRightHeadVars(): void {
$sparqlQuery = "SELECT ?subject ?predicate ?object WHERE { ?subject ?predicate ?object } LIMIT 1";
$data = $this->queryRunner->runQuery( $sparqlQuery );
$data = $this->newQueryRunner()->runQuery( $sparqlQuery );

$this->assertArrayHasKey( 'head', $data );
$this->assertArrayHasKey( 'vars', $data['head'] );
Expand All @@ -44,7 +42,7 @@ public function testRunQueryReturnsRightHeadVars(): void {
public function testRunQueryReturnsRightNoOfResults(): void {
$limit = 3;
$sparqlQuery = "SELECT ?subject ?predicate ?object WHERE { ?subject ?predicate ?object } LIMIT $limit";
$responseData = $this->queryRunner->runQuery( $sparqlQuery );
$responseData = $this->newQueryRunner()->runQuery( $sparqlQuery );

$this->assertArrayHasKey( 'results', $responseData );
$this->assertArrayHasKey( 'bindings', $responseData['results'] );
Expand Down