1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataAccess\Tests; |
4
|
|
|
|
5
|
|
|
use Serializers\Serializer; |
6
|
|
|
use Wikibase\DataAccess\GenericServices; |
7
|
|
|
use Wikibase\DataModel\SerializerFactory; |
8
|
|
|
use Wikibase\Lib\EntityTypeDefinitions; |
9
|
|
|
use Wikibase\Lib\LanguageFallbackChainFactory; |
10
|
|
|
use Wikibase\Lib\StringNormalizer; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \Wikibase\DataAccess\GenericServices |
14
|
|
|
* |
15
|
|
|
* @group Wikibase |
16
|
|
|
* |
17
|
|
|
* @license GPL-2.0-or-later |
18
|
|
|
*/ |
19
|
|
|
class GenericServicesTest extends \PHPUnit\Framework\TestCase { |
20
|
|
|
|
21
|
|
|
public function testGetEntitySerializer() { |
22
|
|
|
$services = $this->newGenericServices(); |
23
|
|
|
$this->assertInstanceOf( Serializer::class, $services->getFullEntitySerializer() ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGetEntitySerializerReusesTheInstanceForMultipleCalls() { |
27
|
|
|
$services = $this->newGenericServices(); |
28
|
|
|
|
29
|
|
|
$serializerOne = $services->getFullEntitySerializer(); |
30
|
|
|
$serializerTwo = $services->getFullEntitySerializer(); |
31
|
|
|
|
32
|
|
|
$this->assertSame( $serializerOne, $serializerTwo ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetCompactEntitySerializer() { |
36
|
|
|
$services = $this->newGenericServices(); |
37
|
|
|
$this->assertInstanceOf( Serializer::class, $services->getCompactEntitySerializer() ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetCompactEntitySerializerReusesTheInstanceForMultipleCalls() { |
41
|
|
|
$services = $this->newGenericServices(); |
42
|
|
|
|
43
|
|
|
$serializerOne = $services->getCompactEntitySerializer(); |
44
|
|
|
$serializerTwo = $services->getCompactEntitySerializer(); |
45
|
|
|
|
46
|
|
|
$this->assertSame( $serializerOne, $serializerTwo ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetStorageEntitySerializer() { |
50
|
|
|
$services = $this->newGenericServices(); |
51
|
|
|
$this->assertInstanceOf( Serializer::class, $services->getStorageEntitySerializer() ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetStorageEntitySerializerReusesTheInstanceForMultipleCalls() { |
55
|
|
|
$services = $this->newGenericServices(); |
56
|
|
|
|
57
|
|
|
$serializerOne = $services->getStorageEntitySerializer(); |
58
|
|
|
$serializerTwo = $services->getStorageEntitySerializer(); |
59
|
|
|
|
60
|
|
|
$this->assertSame( $serializerOne, $serializerTwo ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testGetLanguageFallbackChainFactory() { |
64
|
|
|
$services = $this->newGenericServices(); |
65
|
|
|
|
66
|
|
|
$this->assertInstanceOf( LanguageFallbackChainFactory::class, $services->getLanguageFallbackChainFactory() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetLanguageFallbackChainFactoryReusesTheInstanceForMultipleCalls() { |
70
|
|
|
$services = $this->newGenericServices(); |
71
|
|
|
|
72
|
|
|
$serviceOne = $services->getLanguageFallbackChainFactory(); |
73
|
|
|
$serviceTwo = $services->getLanguageFallbackChainFactory(); |
74
|
|
|
|
75
|
|
|
$this->assertSame( $serviceOne, $serviceTwo ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testGetSerializerFactory() { |
79
|
|
|
$services = $this->newGenericServices(); |
80
|
|
|
$this->assertInstanceOf( SerializerFactory::class, $services->getBaseDataModelSerializerFactory() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetCompactSerializerFactory() { |
84
|
|
|
$services = $this->newGenericServices(); |
85
|
|
|
$this->assertInstanceOf( SerializerFactory::class, $services->getCompactBaseDataModelSerializerFactory() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testGetStringNormalizer() { |
89
|
|
|
$services = $this->newGenericServices(); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf( StringNormalizer::class, $services->getStringNormalizer() ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testGetStringNormalizerReusesTheInstanceForMultipleCalls() { |
95
|
|
|
$services = $this->newGenericServices(); |
96
|
|
|
|
97
|
|
|
$serviceOne = $services->getStringNormalizer(); |
98
|
|
|
$serviceTwo = $services->getStringNormalizer(); |
99
|
|
|
|
100
|
|
|
$this->assertSame( $serviceOne, $serviceTwo ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function newGenericServices() { |
104
|
|
|
return new GenericServices( new EntityTypeDefinitions( [] ), [], [] ); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.