This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Wikibase\DataAccess\Tests; |
||
4 | |||
5 | use DataValues\Deserializers\DataValueDeserializer; |
||
6 | use LogicException; |
||
7 | use MediaWiki\Storage\NameTableStore; |
||
8 | use PHPUnit\Framework\MockObject\MockObject; |
||
9 | use Wikibase\DataAccess\EntitySource; |
||
10 | use Wikibase\DataAccess\GenericServices; |
||
11 | use Wikibase\DataAccess\PrefetchingTermLookup; |
||
12 | use Wikibase\DataAccess\SingleEntitySourceServices; |
||
13 | use Wikibase\DataModel\Entity\BasicEntityIdParser; |
||
14 | use Wikibase\DataModel\Entity\ItemId; |
||
15 | use Wikibase\DataModel\Services\Entity\EntityPrefetcher; |
||
16 | use Wikibase\DataModel\Services\EntityId\EntityIdComposer; |
||
17 | use Wikibase\Lib\EntityTypeDefinitions; |
||
18 | use Wikibase\Lib\Interactors\TermSearchInteractorFactory; |
||
19 | use Wikibase\Lib\Store\EntityRevisionLookup; |
||
20 | use Wikibase\Lib\Store\PropertyInfoLookup; |
||
21 | use Wikibase\Lib\Store\Sql\Terms\TermInLangIdsResolver; |
||
22 | use Wikimedia\Assert\ParameterElementTypeException; |
||
23 | |||
24 | /** |
||
25 | * @covers \Wikibase\DataAccess\SingleEntitySourceServices |
||
26 | * |
||
27 | * @group Wikibase |
||
28 | * |
||
29 | * @license GPL-2.0-or-later |
||
30 | */ |
||
31 | class SingleEntitySourceServicesTest extends \PHPUnit\Framework\TestCase { |
||
32 | |||
33 | public function testValidConstruction() { |
||
34 | $this->newSingleEntitySourceServices(); |
||
35 | $this->assertTrue( true ); |
||
36 | } |
||
37 | |||
38 | public function provideSimpleServiceGetters() { |
||
39 | return [ |
||
40 | [ 'getEntityRevisionLookup', EntityRevisionLookup::class, true ], |
||
41 | [ 'getTermSearchInteractorFactory', TermSearchInteractorFactory::class, true ], |
||
42 | [ 'getPrefetchingTermLookup', PrefetchingTermLookup::class, true ], |
||
43 | [ 'getEntityPrefetcher', EntityPrefetcher::class, true ], |
||
44 | [ 'getPropertyInfoLookup', PropertyInfoLookup::class, true ], |
||
45 | [ 'getEntitySource', EntitySource::class, true ], |
||
46 | [ 'getTermInLangIdsResolver', TermInLangIdsResolver::class, false ], |
||
47 | ]; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @dataProvider provideSimpleServiceGetters |
||
52 | */ |
||
53 | public function testSimpleServiceGetters( $function, $expected, $expectSame ) { |
||
54 | $services = $this->newSingleEntitySourceServices(); |
||
55 | |||
56 | $serviceOne = $services->$function(); |
||
57 | $serviceTwo = $services->$function(); |
||
58 | |||
59 | $this->assertInstanceOf( $expected, $serviceOne ); |
||
60 | |||
61 | if ( $expectSame ) { |
||
62 | $this->assertSame( $serviceOne, $serviceTwo ); |
||
63 | } else { |
||
64 | $this->assertNotSame( $serviceOne, $serviceTwo ); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | public function testGivenEntitySourceDoesNotProvideProperties_getPropertyInfoLookupThrowsException() { |
||
69 | $services = new SingleEntitySourceServices( |
||
70 | $this->newGenericServices(), |
||
71 | new BasicEntityIdParser(), |
||
72 | new EntityIdComposer( [] ), |
||
73 | new DataValueDeserializer( [] ), |
||
74 | $this->getMockNameTableStore(), |
||
75 | DataAccessSettingsFactory::anySettings(), |
||
76 | new EntitySource( 'source', 'sourcedb', [], '', '', '', '' ), |
||
77 | [ 'strval' ], |
||
78 | [], |
||
79 | [], |
||
80 | [] |
||
81 | ); |
||
82 | |||
83 | $this->expectException( LogicException::class ); |
||
84 | $services->getPropertyInfoLookup(); |
||
85 | } |
||
86 | |||
87 | public function testInvalidConstruction_deserializeFactoryCallbacks() { |
||
88 | $this->expectException( ParameterElementTypeException::class ); |
||
89 | new SingleEntitySourceServices( |
||
90 | $this->newGenericServices(), |
||
91 | new BasicEntityIdParser(), |
||
92 | new EntityIdComposer( [] ), |
||
93 | new DataValueDeserializer( [] ), |
||
94 | $this->getMockNameTableStore(), |
||
95 | DataAccessSettingsFactory::anySettings(), |
||
96 | new EntitySource( 'source', 'sourcedb', [], '', '', '', '' ), |
||
97 | [ null ], |
||
98 | [], |
||
99 | [], |
||
100 | [] |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | public function testInvalidConstruction_entityMetaDataAccessorCallbacks() { |
||
105 | $this->expectException( ParameterElementTypeException::class ); |
||
106 | new SingleEntitySourceServices( |
||
107 | $this->newGenericServices(), |
||
108 | new BasicEntityIdParser(), |
||
109 | new EntityIdComposer( [] ), |
||
110 | new DataValueDeserializer( [] ), |
||
111 | $this->getMockNameTableStore(), |
||
112 | DataAccessSettingsFactory::anySettings(), |
||
113 | new EntitySource( 'source', 'sourcedb', [], '', '', '', '' ), |
||
114 | [], |
||
115 | [ null ], |
||
116 | [], |
||
117 | [] |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | public function testInvalidConstruction_prefetchingTermLookupCallbacks() { |
||
122 | $this->expectException( ParameterElementTypeException::class ); |
||
123 | new SingleEntitySourceServices( |
||
124 | $this->newGenericServices(), |
||
125 | new BasicEntityIdParser(), |
||
126 | new EntityIdComposer( [] ), |
||
127 | new DataValueDeserializer( [] ), |
||
128 | $this->getMockNameTableStore(), |
||
129 | DataAccessSettingsFactory::anySettings(), |
||
130 | new EntitySource( 'source', 'sourcedb', [], '', '', '', '' ), |
||
131 | [], |
||
132 | [], |
||
133 | [ null ], |
||
134 | [] |
||
135 | ); |
||
136 | } |
||
137 | |||
138 | public function testGivenCustomLookupConstructingCallbacks_getPrefetchingTermLookupReturnsCustomLookup() { |
||
139 | $customLookup = $this->createMock( PrefetchingTermLookup::class ); |
||
140 | $customLookup->method( $this->anything() ) |
||
141 | ->willReturn( 'CUSTOM' ); |
||
142 | |||
143 | $customItemLookupCallback = function() use ( $customLookup ) { |
||
144 | return $customLookup; |
||
145 | }; |
||
146 | |||
147 | $services = new SingleEntitySourceServices( |
||
148 | $this->newGenericServices(), |
||
149 | new BasicEntityIdParser(), |
||
150 | new EntityIdComposer( [] ), |
||
151 | new DataValueDeserializer( [] ), |
||
152 | $this->getMockNameTableStore(), |
||
153 | DataAccessSettingsFactory::anySettings(), |
||
154 | new EntitySource( |
||
155 | 'source', |
||
156 | 'sourcedb', |
||
157 | [ 'item' => [ 'namespaceId' => 100, 'slot' => 'main' ], 'property' => [ 'namespaceId' => 200, 'slot' => 'main' ] ], |
||
158 | '', |
||
159 | '', |
||
160 | '', |
||
161 | '' |
||
162 | ), |
||
163 | [], |
||
164 | [], |
||
165 | [ 'item' => $customItemLookupCallback ], |
||
166 | [] |
||
167 | ); |
||
168 | |||
169 | $lookup = $services->getPrefetchingTermLookup(); |
||
170 | |||
171 | $this->assertSame( 'CUSTOM', $lookup->getLabel( new ItemId( 'Q123' ), 'fake' ) ); |
||
172 | } |
||
173 | |||
174 | public function newSingleEntitySourceServices() { |
||
175 | return new SingleEntitySourceServices( |
||
176 | $this->newGenericServices(), |
||
177 | new BasicEntityIdParser(), |
||
178 | new EntityIdComposer( [] ), |
||
179 | new DataValueDeserializer( [] ), |
||
180 | $this->getMockNameTableStore(), |
||
181 | DataAccessSettingsFactory::anySettings(), |
||
182 | new EntitySource( 'source', 'sourcedb', [ 'property' => [ 'namespaceId' => 200, 'slot' => 'main' ] ], '', '', '', '' ), |
||
183 | [], |
||
184 | [], |
||
185 | [], |
||
186 | [] |
||
187 | ); |
||
188 | } |
||
189 | |||
190 | public function newGenericServices() { |
||
191 | return new GenericServices( |
||
192 | new EntityTypeDefinitions( [] ), |
||
193 | [], |
||
0 ignored issues
–
show
|
|||
194 | [] |
||
195 | ); |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @return MockObject|NameTableStore |
||
200 | */ |
||
201 | private function getMockNameTableStore() { |
||
202 | $m = $this->getMockBuilder( NameTableStore::class ); |
||
203 | return $m->disableOriginalConstructor()->getMock(); |
||
204 | } |
||
205 | |||
206 | // TODO test entityUpdated |
||
207 | // TODO test redirectUpdated |
||
208 | // TODO test entityDeleted |
||
209 | |||
210 | } |
||
211 |
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.