EntityDifferTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 40
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenUnknownEntityType_exceptionIsThrown() 0 6 1
A testGivenEntitiesWithDifferentTypes_exceptionIsThrown() 0 6 1
A testGivenTwoEmptyItems_emptyItemDiffIsReturned() 0 8 1
A testGivenUnknownEntityType_getConstructionDiffThrowsException() 0 6 1
A testGivenUnknownEntityType_getDestructionDiffThrowsException() 0 6 1
1
<?php
2
3
namespace Wikibase\DataModel\Services\Tests\Diff;
4
5
use InvalidArgumentException;
6
use PHPUnit\Framework\TestCase;
7
use RuntimeException;
8
use Wikibase\DataModel\Entity\Item;
9
use Wikibase\DataModel\Entity\Property;
10
use Wikibase\DataModel\Services\Diff\EntityDiffer;
11
use Wikibase\DataModel\Services\Diff\ItemDiff;
12
use Wikibase\DataModel\Services\Fixtures\EntityOfUnknownType;
13
14
/**
15
 * @covers \Wikibase\DataModel\Services\Diff\EntityDiffer
16
 *
17
 * @license GPL-2.0-or-later
18
 * @author Jeroen De Dauw < [email protected] >
19
 */
20
class EntityDifferTest extends TestCase {
21
22
	public function testGivenUnknownEntityType_exceptionIsThrown() {
23
		$differ = new EntityDiffer();
24
25
		$this->expectException( RuntimeException::class );
26
		$differ->diffEntities( new EntityOfUnknownType(), new EntityOfUnknownType() );
27
	}
28
29
	public function testGivenEntitiesWithDifferentTypes_exceptionIsThrown() {
30
		$differ = new EntityDiffer();
31
32
		$this->expectException( InvalidArgumentException::class );
33
		$differ->diffEntities( new Item(), Property::newFromType( 'string' ) );
34
	}
35
36
	public function testGivenTwoEmptyItems_emptyItemDiffIsReturned() {
37
		$differ = new EntityDiffer();
38
39
		$diff = $differ->diffEntities( new Item(), new Item() );
40
41
		$this->assertInstanceOf( ItemDiff::class, $diff );
42
		$this->assertTrue( $diff->isEmpty() );
43
	}
44
45
	public function testGivenUnknownEntityType_getConstructionDiffThrowsException() {
46
		$differ = new EntityDiffer();
47
48
		$this->expectException( RuntimeException::class );
49
		$differ->getConstructionDiff( new EntityOfUnknownType() );
50
	}
51
52
	public function testGivenUnknownEntityType_getDestructionDiffThrowsException() {
53
		$differ = new EntityDiffer();
54
55
		$this->expectException( RuntimeException::class );
56
		$differ->getDestructionDiff( new EntityOfUnknownType() );
57
	}
58
59
}
60