Passed
Push — undep-item-link-methods ( b0de45...0b2957 )
by no
05:50
created

StatementGuidTest::testEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Statement;
4
5
use Exception;
6
use InvalidArgumentException;
7
use Wikibase\DataModel\Statement\StatementGuid;
8
use Wikibase\DataModel\Entity\EntityId;
9
use Wikibase\DataModel\Entity\ItemId;
10
11
/**
12
 * @covers Wikibase\DataModel\Statement\StatementGuid
13
 *
14
 * @group Wikibase
15
 * @group WikibaseDataModel
16
 *
17
 * @license GPL-2.0+
18
 * @author Addshore
19
 */
20
class StatementGuidTest extends \PHPUnit_Framework_TestCase {
21
22
	/**
23
	 * @dataProvider provideConstructionData
24
	 * @param EntityId $entityId
25
	 * @param string $guid
26
	 * @param string $expected
27
	 */
28
	public function testConstructor( EntityId $entityId, $guid, $expected ) {
29
		$statementGuid = new StatementGuid( $entityId, $guid );
30
31
		$this->assertEquals( $expected, $statementGuid->getSerialization() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\State...uid::getSerialization() has been deprecated with message: The value returned by this method might differ in case from the original, unparsed statement GUID
(the entity ID part might have been lowercase originally, but is always normalized in the return value here),
which means that the value should not be compared to other statement GUID serializations,
e.g. to look up a statement in a StatementList.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
32
		$this->assertEquals( $entityId, $statementGuid->getEntityId() );
33
	}
34
35
	public function provideConstructionData() {
36
		$argLists = [];
37
38
		$argLists[] = [
39
			new ItemId( 'q42' ),
40
			'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ,
41
			'Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0N'
42
		];
43
		$argLists[] = [
44
			new ItemId( 'Q1234567' ),
45
			'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF',
46
			'Q1234567$D4FDE516-F20C-4154-ADCE-7C5B609DFDFF'
47
		];
48
		$argLists[] = [
49
			new ItemId( 'Q1' ),
50
			'foo',
51
			'Q1$foo'
52
		];
53
54
		return $argLists;
55
	}
56
57
	/**
58
	 * @dataProvider provideBadConstruction
59
	 */
60
	public function testBadConstruction( $entityId, $guid ) {
61
		$this->setExpectedException( InvalidArgumentException::class );
62
		new StatementGuid( $entityId, $guid );
63
	}
64
65
	public function provideBadConstruction() {
66
		$argLists = [];
67
68
		$argLists[] = [ 'foobar', 'foobar' ];
69
		$argLists[] = [ 'q123', 'foo' ];
70
		$argLists[] = [ [], 'foo' ];
71
		$argLists[] = [ new Exception(), 'foo' ];
72
		$argLists[] = [ 'bar', 12345 ];
73
74
		return $argLists;
75
	}
76
77
	public function provideStatementGuids() {
78
		$constructionDatas = $this->provideConstructionData();
79
		$argLists = [];
80
81
		foreach ( $constructionDatas as $constructionData ) {
82
			$argLists[] = [ new StatementGuid( $constructionData[0], $constructionData[1] ) ];
83
		}
84
85
		return $argLists;
86
	}
87
88
	/**
89
	 * @dataProvider provideStatementGuids
90
	 *
91
	 * @param StatementGuid $statementGuid
92
	 */
93
	public function testEquals( StatementGuid $statementGuid ) {
94
		$statementGuidCopy = clone $statementGuid;
95
		$this->assertTrue( $statementGuid->equals( $statementGuidCopy ) );
96
		$this->assertTrue( $statementGuidCopy->equals( $statementGuid ) );
97
	}
98
99
	/**
100
	 * @dataProvider provideStatementGuids
101
	 *
102
	 * @param StatementGuid $statementGuid
103
	 */
104
	public function testNotEquals( StatementGuid $statementGuid ) {
105
		$notEqualStatementGuid = new StatementGuid( new ItemId( 'q9999' ), 'someguid' );
106
		$this->assertFalse( $statementGuid->equals( $notEqualStatementGuid ) );
107
		$this->assertFalse( $notEqualStatementGuid->equals( $statementGuid ) );
108
	}
109
110
}
111