1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Diff; |
4
|
|
|
|
5
|
|
|
use Diff\DiffOp\Diff\Diff; |
6
|
|
|
use Diff\DiffOp\DiffOpAdd; |
7
|
|
|
use Diff\DiffOp\DiffOpChange; |
8
|
|
|
use Diff\DiffOp\DiffOpRemove; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Wikibase\DataModel\Entity\Item; |
11
|
|
|
use Wikibase\DataModel\Services\Diff\ItemDiff; |
12
|
|
|
use Wikibase\DataModel\Services\Diff\ItemDiffer; |
13
|
|
|
use Wikibase\DataModel\Snak\PropertySomeValueSnak; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \Wikibase\DataModel\Services\Diff\ItemDiffer |
17
|
|
|
* @covers \Wikibase\DataModel\Services\Diff\ItemDiff |
18
|
|
|
* |
19
|
|
|
* @license GPL-2.0-or-later |
20
|
|
|
* @author Jeroen De Dauw < [email protected] > |
21
|
|
|
*/ |
22
|
|
|
class ItemDifferTest extends TestCase { |
23
|
|
|
|
24
|
|
|
public function testGivenTwoEmptyItems_emptyItemDiffIsReturned() { |
25
|
|
|
$differ = new ItemDiffer(); |
26
|
|
|
|
27
|
|
|
$diff = $differ->diffEntities( new Item(), new Item() ); |
28
|
|
|
|
29
|
|
|
$this->assertInstanceOf( ItemDiff::class, $diff ); |
30
|
|
|
$this->assertTrue( $diff->isEmpty() ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testFingerprintIsDiffed() { |
34
|
|
|
$firstItem = new Item(); |
35
|
|
|
$firstItem->setLabel( 'en', 'kittens' ); |
36
|
|
|
$firstItem->setAliases( 'en', [ 'cats' ] ); |
37
|
|
|
|
38
|
|
|
$secondItem = new Item(); |
39
|
|
|
$secondItem->getFingerprint()->setLabel( 'en', 'nyan' ); |
40
|
|
|
$secondItem->getFingerprint()->setDescription( 'en', 'foo bar baz' ); |
41
|
|
|
|
42
|
|
|
$differ = new ItemDiffer(); |
43
|
|
|
$diff = $differ->diffItems( $firstItem, $secondItem ); |
44
|
|
|
|
45
|
|
|
$this->assertEquals( |
46
|
|
|
new Diff( [ 'en' => new DiffOpChange( 'kittens', 'nyan' ) ] ), |
47
|
|
|
$diff->getLabelsDiff() |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->assertEquals( |
51
|
|
|
new Diff( [ 'en' => new DiffOpAdd( 'foo bar baz' ) ] ), |
52
|
|
|
$diff->getDescriptionsDiff() |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->assertEquals( |
56
|
|
|
new Diff( [ 'en' => new Diff( [ new DiffOpRemove( 'cats' ) ] ) ] ), |
57
|
|
|
$diff->getAliasesDiff() |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testClaimsAreDiffed() { |
62
|
|
|
$firstItem = new Item(); |
63
|
|
|
|
64
|
|
|
$secondItem = new Item(); |
65
|
|
|
$secondItem->getStatements()->addNewStatement( new PropertySomeValueSnak( 42 ), null, null, 'guid' ); |
66
|
|
|
|
67
|
|
|
$differ = new ItemDiffer(); |
68
|
|
|
$diff = $differ->diffItems( $firstItem, $secondItem ); |
69
|
|
|
|
70
|
|
|
$this->assertCount( 1, $diff->getClaimsDiff()->getAdditions() ); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testGivenEmptyItem_constructionDiffIsEmpty() { |
74
|
|
|
$differ = new ItemDiffer(); |
75
|
|
|
$this->assertTrue( $differ->getConstructionDiff( new Item() )->isEmpty() ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testGivenEmptyItem_destructionDiffIsEmpty() { |
79
|
|
|
$differ = new ItemDiffer(); |
80
|
|
|
$this->assertTrue( $differ->getDestructionDiff( new Item() )->isEmpty() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testConstructionDiffContainsAddOperations() { |
84
|
|
|
$item = new Item(); |
85
|
|
|
$item->getFingerprint()->setLabel( 'en', 'foo' ); |
86
|
|
|
$item->getSiteLinkList()->addNewSiteLink( 'bar', 'baz' ); |
87
|
|
|
|
88
|
|
|
$differ = new ItemDiffer(); |
89
|
|
|
$diff = $differ->getConstructionDiff( $item ); |
90
|
|
|
|
91
|
|
|
$this->assertEquals( |
92
|
|
|
new Diff( [ 'en' => new DiffOpAdd( 'foo' ) ] ), |
93
|
|
|
$diff->getLabelsDiff() |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$this->assertEquals( |
97
|
|
|
new Diff( [ 'bar' => new Diff( [ 'name' => new DiffOpAdd( 'baz' ) ] ) ] ), |
98
|
|
|
$diff->getSiteLinkDiff() |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: