Passed
Push — currentLimits ( 82fe71...f9050f )
by no
03:50
created

EntityRedirectTest::testToString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Entity;
4
5
use Wikibase\DataModel\Entity\EntityRedirect;
6
use Wikibase\DataModel\Entity\ItemId;
7
use Wikibase\DataModel\Entity\PropertyId;
8
9
/**
10
 * @covers Wikibase\DataModel\Entity\EntityRedirect
11
 *
12
 * @group Wikibase
13
 * @group WikibaseDataModel
14
 *
15
 * @license GPL-2.0+
16
 * @author Daniel Kinzler
17
 */
18
class EntityRedirectTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testConstruction() {
21
		$entityId = new ItemId( 'Q123' );
22
		$targetId = new ItemId( 'Q345' );
23
24
		$redirect = new EntityRedirect( $entityId, $targetId );
25
26
		$this->assertEquals( $entityId, $redirect->getEntityId(), '$redirect->getEntityId()' );
27
		$this->assertEquals( $targetId, $redirect->getTargetId(), '$redirect->getTargetId()' );
28
	}
29
30
	public function testConstruction_baseType() {
31
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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
33
		$entityId = new ItemId( 'Q123' );
34
		$targetId = new PropertyId( 'P345' );
35
36
		new EntityRedirect( $entityId, $targetId );
37
	}
38
39
	public function equalsProvider() {
40
		$q123 = new ItemId( 'Q123' );
41
		$q345 = new ItemId( 'Q345' );
42
		$q567 = new ItemId( 'Q567' );
43
		$q123_345 = new EntityRedirect( $q123, $q345 );
44
45
		$p123 = new PropertyId( 'P123' );
46
		$p345 = new PropertyId( 'P345' );
47
		$p123_345 = new EntityRedirect( $p123, $p345 );
48
49
		return array(
50
			'same' => array( $q123_345, $q123_345, true ),
51
			'equal' => array( $q123_345, new EntityRedirect( $q123, $q345 ), true ),
52
53
			'different base' => array( $q123_345, new EntityRedirect( $q567, $q345 ), false ),
54
			'different target' => array( $q123_345, new EntityRedirect( $q123, $q567 ), false ),
55
56
			'different entity type' => array( $q123_345, $p123_345, false ),
57
			'different number' => array( $q123_345, new EntityRedirect( $q345, $q123 ), false ),
58
59
			'null' => array( $q123_345, null, false ),
60
			'string' => array( $q123_345, 'foo', false ),
61
			'id' => array( $q123_345, $q123, false ),
62
		);
63
	}
64
65
	/**
66
	 * @dataProvider equalsProvider
67
	 *
68
	 * @param EntityRedirect $a
69
	 * @param mixed $b
70
	 * @param bool $expected
71
	 */
72
	public function testEquals( $a, $b, $expected ) {
73
		$this->assertEquals( $expected, $a->equals( $b ), '$a->equals( $b )' );
74
75
		if ( $b instanceof EntityRedirect ) {
76
			$this->assertEquals( $expected, $b->equals( $a ), '$b->equals( $a )' );
77
		}
78
	}
79
80
	public function testToString() {
81
		$redirect = new EntityRedirect( new ItemId( 'Q1' ), new ItemId( 'Q2' ) );
82
		$this->assertSame( 'Q1->Q2', $redirect->__toString() );
83
	}
84
85
}
86