testWhenInsertingBerlin_entityStoreFieldsAreSet()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Tests\Queryr\Replicator\Integration\Importer;
4
5
use PHPUnit\Framework\TestCase;
6
use Queryr\Replicator\EntitySource\Api\GetEntitiesInterpreter;
7
use Queryr\Replicator\Importer\EntityHandlers\EntityStoreEntityHandler;
8
use Queryr\Replicator\Importer\EntityHandlers\QueryEngineEntityHandler;
9
use Queryr\Replicator\Importer\EntityHandlers\TermStoreEntityHandler;
10
use Queryr\Replicator\Importer\PageImporter;
11
use Queryr\Replicator\Importer\PageImportReporter;
12
use Queryr\Replicator\ServiceFactory;
13
use Tests\Queryr\Replicator\Integration\TestEnvironment;
14
15
/**
16
 * @licence GNU GPL v2+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class PageImporterTest extends TestCase {
20
21
	public function testWhenInsertingBerlin_entityStoreFieldsAreSet() {
22
		$factory = TestEnvironment::newInstance()->getFactory();
23
24
		$pageImporter = new PageImporter(
25
			$factory->newLegacyEntityDeserializer(),
26
			$this->getEntityHandlers( $factory ),
27
			[
28
				new EntityStoreEntityHandler( $factory->newEntityStore() )
29
			],
30
			$this->createMock( PageImportReporter::class )
0 ignored issues
show
Documentation introduced by
$this->createMock(\Query...eImportReporter::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Queryr\Replicator...ter\PageImportReporter>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
		);
32
33
		$jsonString = file_get_contents( __DIR__ . '/../../data/api/Q64.json' );
34
		$entityPages = ( new GetEntitiesInterpreter() )->getEntityPagesFromResult( $jsonString );
35
36
		foreach ( $entityPages as $entityPage ) {
37
			$pageImporter->import( $entityPage );
38
		}
39
40
		$itemStore = $factory->newItemStore();
41
42
		$itemRow = $itemStore->getItemRowByNumericItemId( 64 );
43
44
		$this->assertSame( 64, $itemRow->getNumericItemId() );
45
		$this->assertSame( 'Q64', $itemRow->getPageTitle() );
46
		$this->assertSame( 515, $itemRow->getItemType() );
47
		$this->assertSame( 'Berlin', $itemRow->getEnglishLabel() );
48
		$this->assertSame( 'Berlin', $itemRow->getEnglishWikipediaTitle() );
49
50
		$this->assertInternalType( 'array', json_decode( $itemRow->getItemJson(), true ) );
51
	}
52
53
	private function getEntityHandlers( ServiceFactory $factory ) {
54
		$handlers = [
55
			new TermStoreEntityHandler( $factory->newTermStoreWriter() )
56
		];
57
58
		if ( defined( 'WIKIBASE_QUERYENGINE_VERSION' ) ) {
59
			$handlers[] = new QueryEngineEntityHandler( $factory->newQueryStoreWriter() );
60
		}
61
62
		return $handlers;
63
	}
64
}
65