Skip to content

Commit 799be75

Browse files
Change some assertEquals to assertSame
This is a good practice in general, but also has the added benefit of pushing one long line just below 120 characters, avoiding a phpcs warning. These changes include some assertions where the values being compared are objects, i.e. we now compare their identity. This is certainly debatable, but I think that in some cases, it makes sense that a “container” object, like a StatementList, the objects coming out of the container are identical, not just equal, to the ones put in. On the other hand, this is certainly a bit fuzzy and debatable (they’re not generic containers – why shouldn’t they be allowed to store their contents in a more efficient form and return new but equal objects later?), and I doubt I’ve been fully consistent here either, so this can also be changed later. Bug: T253636
1 parent 3fcd2d3 commit 799be75

22 files changed

Lines changed: 54 additions & 54 deletions

tests/unit/Entity/EntityIdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testSerializationStability() {
7272
$serialization = 'C:32:"Wikibase\DataModel\Entity\ItemId":4:{Q123}';
7373
$id = new ItemId( 'q123' );
7474

75-
$this->assertEquals(
75+
$this->assertSame(
7676
serialize( $id ),
7777
$serialization
7878
);

tests/unit/Entity/EntityIdValueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function instanceProvider() {
6262
* @dataProvider instanceProvider
6363
*/
6464
public function testGetType( EntityIdValue $id ) {
65-
$this->assertEquals( 'wikibase-entityid', $id->getType() );
65+
$this->assertSame( 'wikibase-entityid', $id->getType() );
6666
}
6767

6868
/**

tests/unit/Entity/EntityRedirectTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public function equalsProvider() {
8080
* @param bool $expected
8181
*/
8282
public function testEquals( EntityRedirect $a, $b, $expected ) {
83-
$this->assertEquals( $expected, $a->equals( $b ), '$a->equals( $b )' );
83+
$this->assertSame( $expected, $a->equals( $b ), '$a->equals( $b )' );
8484

8585
if ( $b instanceof EntityRedirect ) {
86-
$this->assertEquals( $expected, $b->equals( $a ), '$b->equals( $a )' );
86+
$this->assertSame( $expected, $b->equals( $a ), '$b->equals( $a )' );
8787
}
8888
}
8989

tests/unit/Entity/ItemIdSetTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testGetIterator() {
2727
*/
2828
public function testGetSerializations( array $itemIds, array $expected ) {
2929
$set = new ItemIdSet( $itemIds );
30-
$this->assertEquals( $expected, $set->getSerializations() );
30+
$this->assertSame( $expected, $set->getSerializations() );
3131
}
3232

3333
public function serializationsProvider() {
@@ -48,7 +48,7 @@ public function testGivenSetWithTwoItems_countReturnsTwo() {
4848
new ItemId( 'Q1' ),
4949
new ItemId( 'Q2' ),
5050
] );
51-
$this->assertEquals( 2, $set->count() );
51+
$this->assertSame( 2, $set->count() );
5252
}
5353

5454
public function testGivenNotSetId_hasReturnsFalse() {

tests/unit/Entity/ItemIdTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ItemIdTest extends \PHPUnit\Framework\TestCase {
2323
public function testCanConstructId( $idSerialization, $normalizedIdSerialization ) {
2424
$id = new ItemId( $idSerialization );
2525

26-
$this->assertEquals(
26+
$this->assertSame(
2727
$normalizedIdSerialization,
2828
$id->getSerialization()
2929
);
@@ -123,7 +123,7 @@ public function serializationProvider() {
123123
*/
124124
public function testNewFromNumber( $number ) {
125125
$id = ItemId::newFromNumber( $number );
126-
$this->assertEquals( 'Q' . $number, $id->getSerialization() );
126+
$this->assertSame( 'Q' . $number, $id->getSerialization() );
127127
}
128128

129129
public function numericIdProvider() {

tests/unit/Entity/PropertyIdTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PropertyIdTest extends \PHPUnit\Framework\TestCase {
2323
public function testCanConstructId( $idSerialization, $normalizedIdSerialization ) {
2424
$id = new PropertyId( $idSerialization );
2525

26-
$this->assertEquals(
26+
$this->assertSame(
2727
$normalizedIdSerialization,
2828
$id->getSerialization()
2929
);
@@ -123,7 +123,7 @@ public function serializationProvider() {
123123
*/
124124
public function testNewFromNumber( $number ) {
125125
$id = PropertyId::newFromNumber( $number );
126-
$this->assertEquals( 'P' . $number, $id->getSerialization() );
126+
$this->assertSame( 'P' . $number, $id->getSerialization() );
127127
}
128128

129129
public function numericIdProvider() {

tests/unit/Entity/PropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public function testClear( Property $property ) {
617617
$property->getId(),
618618
'cleared Property should keep its id'
619619
);
620-
$this->assertEquals(
620+
$this->assertSame(
621621
$clone->getDataTypeId(),
622622
$property->getDataTypeId(),
623623
'cleared Property should keep its data type'

tests/unit/Internal/MapValueHasherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function testHash() {
4040
unset( $map1['foo'] );
4141
$map1[] = $map0['foo'];
4242

43-
$this->assertEquals( $hash, $hasher->hash( $map1 ) );
43+
$this->assertSame( $hash, $hasher->hash( $map1 ) );
4444

4545
$map4 = new ArrayObject( $map0 );
46-
$this->assertEquals( $hash, $hasher->hash( $map4 ) );
46+
$this->assertSame( $hash, $hasher->hash( $map4 ) );
4747

4848
$map2 = $map0;
4949
unset( $map2['foo'] );

tests/unit/ReferenceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ public function testGetHashReturnsString( Reference $reference ) {
9292
* @dataProvider instanceProvider
9393
*/
9494
public function testGetHashIsStable( Reference $reference ) {
95-
$this->assertEquals( $reference->getHash(), $reference->getHash() );
95+
$this->assertSame( $reference->getHash(), $reference->getHash() );
9696
}
9797

9898
/**
9999
* @dataProvider instanceProvider
100100
*/
101101
public function testGetHashIsTheSameForInstanceWithSameValue( Reference $reference ) {
102102
$newRef = unserialize( serialize( $reference ) );
103-
$this->assertEquals( $newRef->getHash(), $reference->getHash() );
103+
$this->assertSame( $newRef->getHash(), $reference->getHash() );
104104
}
105105

106106
/**
@@ -174,7 +174,7 @@ public function unorderedReferenceProvider() {
174174
* @dataProvider unorderedReferenceProvider
175175
*/
176176
public function testUnorderedReference( Reference $unorderedReference, Reference $orderedReference ) {
177-
$this->assertEquals( $unorderedReference->getHash(), $orderedReference->getHash() );
177+
$this->assertSame( $unorderedReference->getHash(), $orderedReference->getHash() );
178178
}
179179

180180
public function testReferenceEqualsItself() {

tests/unit/SiteLinkTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCanConstruct() {
3131
*/
3232
public function testGetSiteId( $siteId ) {
3333
$siteLink = new SiteLink( $siteId, 'Wikidata' );
34-
$this->assertEquals( $siteId, $siteLink->getSiteId() );
34+
$this->assertSame( $siteId, $siteLink->getSiteId() );
3535
}
3636

3737
public function siteIdProvider() {
@@ -67,7 +67,7 @@ public function invalidStringIdentifierProvider() {
6767
*/
6868
public function testGetPageName( $pageName ) {
6969
$siteLink = new SiteLink( 'enwiki', $pageName );
70-
$this->assertEquals( $pageName, $siteLink->getPageName() );
70+
$this->assertSame( $pageName, $siteLink->getPageName() );
7171
}
7272

7373
public function pageNameProvider() {

0 commit comments

Comments
 (0)