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\DataModel\Services\Tests\Lookup; |
||
4 | |||
5 | use PHPUnit\Framework\TestCase; |
||
6 | use Wikibase\DataModel\Entity\PropertyId; |
||
7 | use Wikibase\DataModel\Services\Fixtures\PropertyFixtures; |
||
8 | use Wikibase\DataModel\Services\Lookup\EntityLookupException; |
||
9 | use Wikibase\DataModel\Services\Lookup\InMemoryEntityLookup; |
||
10 | use Wikibase\DataModel\Services\Lookup\LegacyAdapterPropertyLookup; |
||
11 | use Wikibase\DataModel\Services\Lookup\PropertyLookupException; |
||
12 | |||
13 | /** |
||
14 | * @covers \Wikibase\DataModel\Services\Lookup\LegacyAdapterPropertyLookup |
||
15 | * |
||
16 | * @license GPL-2.0-or-later |
||
17 | * @author Jeroen De Dauw < [email protected] > |
||
18 | */ |
||
19 | class LegacyAdapterPropertyLookupTest extends TestCase { |
||
20 | |||
21 | public function testGivenKnownProperty_getPropertyForIdReturnsIt() { |
||
22 | $property = PropertyFixtures::newProperty(); |
||
23 | |||
24 | $lookup = new LegacyAdapterPropertyLookup( new InMemoryEntityLookup( $property ) ); |
||
25 | |||
26 | $this->assertEquals( |
||
27 | $property, |
||
28 | $lookup->getPropertyForId( $property->getId() ) |
||
0 ignored issues
–
show
|
|||
29 | ); |
||
30 | } |
||
31 | |||
32 | public function testWhenPropertyIsNotKnown_getPropertyForIdReturnsNull() { |
||
33 | $lookup = new LegacyAdapterPropertyLookup( new InMemoryEntityLookup() ); |
||
34 | |||
35 | $this->assertNull( |
||
36 | $lookup->getPropertyForId( new PropertyId( 'P1' ) ) |
||
37 | ); |
||
38 | } |
||
39 | |||
40 | public function testGetPropertyForIdThrowsCorrectExceptionType() { |
||
41 | $id = new PropertyId( 'P1' ); |
||
42 | |||
43 | $legacyLookup = new InMemoryEntityLookup(); |
||
44 | $legacyLookup->addException( new EntityLookupException( $id ) ); |
||
45 | |||
46 | $propertyLookup = new LegacyAdapterPropertyLookup( $legacyLookup ); |
||
47 | |||
48 | $this->expectException( PropertyLookupException::class ); |
||
49 | $propertyLookup->getPropertyForId( $id ); |
||
50 | } |
||
51 | |||
52 | } |
||
53 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: