testEnvironment = new TestEnvironment(); $this->store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->testEnvironment->registerObject( 'Store', $this->store ); } protected function tearDown(): void { $this->testEnvironment->tearDown(); parent::tearDown(); } public function testCanConstruct() { $this->assertInstanceOf( QuerySourceFactory::class, new QuerySourceFactory( $this->store ) ); } public function testGetFromFakeSource() { $instance = new QuerySourceFactory( $this->store, [ 'foo' => FakeQueryEngine::class ] ); $this->assertInstanceOf( '\SMW\QueryEngine', $instance->get( 'foo' ) ); } public function testGetStandardStore() { $instance = new QuerySourceFactory( $this->store, [] ); $this->assertInstanceOf( '\SMW\SQLStore\SQLStore', $instance->get( 'sql_store' ) ); $this->assertEquals( 'SMWSQLStore', $instance->toString( 'sql_store' ) ); } public function testGetAsString() { $store = $this->getMockBuilder( '\SMW\SPARQLStore\SPARQLStore' ) ->disableOriginalConstructor() ->getMock(); $store->expects( $this->once() ) ->method( 'getInfo' ) ->willReturn( [ 'SPARQLStore' ] ); $instance = new QuerySourceFactory( $store, [] ); $this->assertContains( 'SPARQLStore', $instance->toString() ); } public function testGetFromAnotherFakeSourceThatImplementsStoreAware() { $store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->setMethods( [ 'getConnection' ] ) ->getMockForAbstractClass(); $store->expects( $this->once() ) ->method( 'getConnection' ) ->with( $this->stringContains( 'foo' ) ); $instance = new QuerySourceFactory( $store, [ 'bar' => AnotherFakeQueryEngine::class ] ); $this->assertInstanceOf( '\SMW\QueryEngine', $instance->get( 'bar' ) ); } } class FakeQueryEngine implements QueryEngine { public function getQueryResult( Query $query ) { return ''; } } class AnotherFakeQueryEngine extends FakeQueryEngine implements StoreAware { public function setStore( Store $store ) { return $store->getConnection( 'foo' ); } }