StatementGuidTest::provideStatementGuids()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Statement;
4
5
use InvalidArgumentException;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\DataModel\Entity\ItemId;
8
use Wikibase\DataModel\Statement\StatementGuid;
9
10
/**
11
 * @covers \Wikibase\DataModel\Statement\StatementGuid
12
 *
13
 * @group Wikibase
14
 * @group WikibaseDataModel
15
 *
16
 * @license GPL-2.0-or-later
17
 * @author Addshore
18
 */
19
class StatementGuidTest extends \PHPUnit\Framework\TestCase {
20
21
	/**
22
	 * @dataProvider provideConstructionData
23
	 */
24
	public function testConstructor( EntityId $entityId, $guid, $expected ) {
25
		$statementGuid = new StatementGuid( $entityId, $guid );
26
27
		$this->assertSame( $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...
28
		$this->assertEquals( $entityId, $statementGuid->getEntityId() );
29
		$this->assertSame( $guid, $statementGuid->getGuidPart() );
30
	}
31
32
	public function provideConstructionData() {
33
		return [
34
			[
35
				new ItemId( 'q42' ),
36
				'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ,
37
				'Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0N'
38
			],
39
			[
40
				new ItemId( 'Q1234567' ),
41
				'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF',
42
				'Q1234567$D4FDE516-F20C-4154-ADCE-7C5B609DFDFF'
43
			],
44
			[
45
				new ItemId( 'Q1' ),
46
				'foo',
47
				'Q1$foo'
48
			],
49
		];
50
	}
51
52
	/**
53
	 * @dataProvider provideBadConstruction
54
	 */
55
	public function testBadConstruction( EntityId $entityId, $guid ) {
56
		$this->expectException( InvalidArgumentException::class );
57
		new StatementGuid( $entityId, $guid );
58
	}
59
60
	public function provideBadConstruction() {
61
		$id = new ItemId( 'Q1' );
62
63
		return [
64
			[ $id, null ],
65
			[ $id, 12345 ],
66
		];
67
	}
68
69
	public function provideStatementGuids() {
70
		$argLists = [];
71
72
		foreach ( $this->provideConstructionData() as $data ) {
73
			$argLists[] = [ new StatementGuid( $data[0], $data[1] ) ];
74
		}
75
76
		return $argLists;
77
	}
78
79
	/**
80
	 * @dataProvider provideStatementGuids
81
	 */
82
	public function testEquals( StatementGuid $statementGuid ) {
83
		$statementGuidCopy = clone $statementGuid;
84
		$this->assertTrue( $statementGuid->equals( $statementGuidCopy ) );
85
		$this->assertTrue( $statementGuidCopy->equals( $statementGuid ) );
86
	}
87
88
	/**
89
	 * @dataProvider provideStatementGuids
90
	 */
91
	public function testNotEquals( StatementGuid $statementGuid ) {
92
		$notEqualStatementGuid = new StatementGuid( new ItemId( 'q9999' ), 'someguid' );
93
		$this->assertFalse( $statementGuid->equals( $notEqualStatementGuid ) );
94
		$this->assertFalse( $notEqualStatementGuid->equals( $statementGuid ) );
95
	}
96
97
}
98