|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\InternalSerialization\Deserializers; |
|
4
|
|
|
|
|
5
|
|
|
use Deserializers\Deserializer; |
|
6
|
|
|
use Deserializers\Exceptions\DeserializationException; |
|
7
|
|
|
use Tests\Integration\Wikibase\InternalSerialization\TestFactoryBuilder; |
|
8
|
|
|
use Wikibase\DataModel\Entity\Item; |
|
9
|
|
|
use Wikibase\DataModel\Entity\Property; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers Wikibase\InternalSerialization\Deserializers\LegacyEntityDeserializer |
|
13
|
|
|
* |
|
14
|
|
|
* @license GPL-2.0-or-later |
|
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
16
|
|
|
*/ |
|
17
|
|
|
class LegacyEntityDeserializerTest extends \PHPUnit\Framework\TestCase { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Deserializer |
|
21
|
|
|
*/ |
|
22
|
|
|
private $deserializer; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() : void { |
|
25
|
|
|
$this->deserializer = TestFactoryBuilder::newLegacyDeserializerFactory( $this )->newEntityDeserializer(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testGivenPropertySerialization_propertyIsReturned() { |
|
29
|
|
|
$serialization = array( |
|
30
|
|
|
'entity' => 'P42', |
|
31
|
|
|
'datatype' => 'foo', |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$deserialized = $this->deserializer->deserialize( $serialization ); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertInstanceOf( Property::class, $deserialized ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGivenItemSerialization_itemIsReturned() { |
|
40
|
|
|
$serialization = array( |
|
41
|
|
|
'entity' => 'Q42', |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$deserialized = $this->deserializer->deserialize( $serialization ); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertInstanceOf( Item::class, $deserialized ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @dataProvider invalidSerializationProvider |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testGivenInvalidSerialization_exceptionIsThrown( $serialization ) { |
|
53
|
|
|
$this->expectException( DeserializationException::class ); |
|
54
|
|
|
$this->deserializer->deserialize( $serialization ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function invalidSerializationProvider() { |
|
58
|
|
|
return array( |
|
59
|
|
|
array( null ), |
|
60
|
|
|
array( 5 ), |
|
61
|
|
|
array( array( 'entity' => 'P42', 'datatype' => null ) ), |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|