1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Diff; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use RuntimeException; |
7
|
|
|
use Wikibase\DataModel\Entity\Item; |
8
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
9
|
|
|
use Wikibase\DataModel\Services\Diff\EntityDiff; |
10
|
|
|
use Wikibase\DataModel\Services\Diff\EntityPatcher; |
11
|
|
|
use Wikibase\DataModel\Services\Diff\ItemDiff; |
12
|
|
|
use Wikibase\DataModel\Services\Fixtures\EntityOfUnknownType; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \Wikibase\DataModel\Services\Diff\EntityPatcher |
16
|
|
|
* |
17
|
|
|
* @license GPL-2.0-or-later |
18
|
|
|
* @author Christoph Fischer < [email protected] > |
19
|
|
|
* @author Jeroen De Dauw < [email protected] > |
20
|
|
|
*/ |
21
|
|
|
class EntityPatcherTest extends TestCase { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @dataProvider itemProvider |
25
|
|
|
*/ |
26
|
|
|
public function testGivenEmptyDiffItemRemainsUnchanged( Item $item ) { |
27
|
|
|
$patcher = new EntityPatcher(); |
28
|
|
|
|
29
|
|
|
$patchedEntity = $item->copy(); |
30
|
|
|
$patcher->patchEntity( $patchedEntity, new ItemDiff() ); |
31
|
|
|
|
32
|
|
|
$this->assertEquals( $item, $patchedEntity ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function itemProvider() { |
36
|
|
|
$argLists = []; |
37
|
|
|
|
38
|
|
|
$nonEmptyItem = new Item( new ItemId( 'Q2' ) ); |
39
|
|
|
|
40
|
|
|
$argLists[] = [ new Item() ]; |
41
|
|
|
$argLists[] = [ $nonEmptyItem ]; |
42
|
|
|
|
43
|
|
|
return $argLists; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGivenNonSupportedEntity_exceptionIsThrown() { |
47
|
|
|
$patcher = new EntityPatcher(); |
48
|
|
|
|
49
|
|
|
$this->expectException( RuntimeException::class ); |
50
|
|
|
$patcher->patchEntity( new EntityOfUnknownType(), new EntityDiff() ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|