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\ItemId; |
||
7 | use Wikibase\DataModel\Services\Fixtures\ItemFixtures; |
||
8 | use Wikibase\DataModel\Services\Lookup\EntityLookupException; |
||
9 | use Wikibase\DataModel\Services\Lookup\InMemoryEntityLookup; |
||
10 | use Wikibase\DataModel\Services\Lookup\ItemLookupException; |
||
11 | use Wikibase\DataModel\Services\Lookup\LegacyAdapterItemLookup; |
||
12 | |||
13 | /** |
||
14 | * @covers \Wikibase\DataModel\Services\Lookup\LegacyAdapterItemLookup |
||
15 | * |
||
16 | * @license GPL-2.0-or-later |
||
17 | * @author Jeroen De Dauw < [email protected] > |
||
18 | */ |
||
19 | class LegacyAdapterItemLookupTest extends TestCase { |
||
20 | |||
21 | public function testGivenKnownItem_getItemForIdReturnsIt() { |
||
22 | $item = ItemFixtures::newItem(); |
||
23 | |||
24 | $lookup = new LegacyAdapterItemLookup( new InMemoryEntityLookup( $item ) ); |
||
25 | |||
26 | $this->assertEquals( |
||
27 | $item, |
||
28 | $lookup->getItemForId( $item->getId() ) |
||
0 ignored issues
–
show
|
|||
29 | ); |
||
30 | } |
||
31 | |||
32 | public function testWhenItemIsNotKnown_getItemForIdReturnsNull() { |
||
33 | $lookup = new LegacyAdapterItemLookup( new InMemoryEntityLookup() ); |
||
34 | |||
35 | $this->assertNull( |
||
36 | $lookup->getItemForId( new ItemId( 'Q1' ) ) |
||
37 | ); |
||
38 | } |
||
39 | |||
40 | public function testGetItemForIdThrowsCorrectExceptionType() { |
||
41 | $id = new ItemId( 'Q1' ); |
||
42 | |||
43 | $legacyLookup = new InMemoryEntityLookup(); |
||
44 | $legacyLookup->addException( new EntityLookupException( $id ) ); |
||
45 | |||
46 | $itemLookup = new LegacyAdapterItemLookup( $legacyLookup ); |
||
47 | |||
48 | $this->expectException( ItemLookupException::class ); |
||
49 | $itemLookup->getItemForId( $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: