Completed
Pull Request — master (#603)
by no
06:45 queued 03:38
created

tests/unit/HashableObjectStorageTest.php (15 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Wikibase\DataModel\Tests;
4
5
use Wikibase\DataModel\Fixtures\HashableObject;
6
use Wikibase\DataModel\HashableObjectStorage;
7
8
/**
9
 * @covers Wikibase\DataModel\HashableObjectStorage
10
 *
11
 * @group Wikibase
12
 * @group WikibaseDataModel
13
 * @group HashableObjectStorageTest
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class HashableObjectStorageTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testRemoveDuplicates() {
21
		$list = new HashableObjectStorage();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\HashableObjectStorage has been deprecated with message: since 4.4, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
22
23
		$list->attach( new HashableObject( 1 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
24
		$list->attach( new HashableObject( 2 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
25
		$list->attach( new HashableObject( 3 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
26
27
		$this->assertEquals(
28
			3,
29
			count( $list ),
30
			'Adding 3 elements should result in a size of 3'
31
		);
32
33
		$list->removeDuplicates();
34
35
		$this->assertEquals(
36
			3,
37
			count( $list ),
38
			'Removing duplicates from a HashableObjectStorage without duplicates should not alter its size'
39
		);
40
41
		$list->attach( new HashableObject( 1 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
42
		$list->attach( new HashableObject( 2 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
43
		$list->attach( new HashableObject( 4 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
44
45
		$this->assertEquals(
46
			6,
47
			count( $list ),
48
			'Adding duplicates to HashableObjectStorage should increase its size'
49
		);
50
51
		$list->removeDuplicates();
52
53
		$this->assertEquals(
54
			4,
55
			count( $list ),
56
			'Removing duplicates from a HashableObjectStorage with duplicates should decrease its size'
57
		);
58
	}
59
60
	public function testGetValueHash() {
61
		$list = new HashableObjectStorage();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\HashableObjectStorage has been deprecated with message: since 4.4, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
62
		$originalList = clone $list;
63
64
		$hash = $list->getValueHash();
65
		$this->assertInternalType( 'string', $hash );
66
67
		$one = new HashableObject( 1 );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
68
		$two = new HashableObject( 1 );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
69
70
		$list->attach( $one );
71
		$list->attach( $two );
72
73
		$newHash = $list->getValueHash();
74
75
		$this->assertNotEquals(
76
			$hash,
77
			$newHash,
78
			'The hash of HashableObjectStorage with different content should be different'
79
		);
80
81
		$this->assertFalse( $list->equals( $originalList ) );
82
83
		$originalList = clone $list;
84
85
		$list->detach( $one );
86
		$list->detach( $two );
87
88
		$list->attach( $two );
89
		$list->attach( $one );
90
91
		$this->assertEquals(
92
			$newHash,
93
			$list->getValueHash(),
94
			'The hash of HashableObjectStorage with the same elements in different order should be the same'
95
		);
96
97
		$this->assertTrue( $list->equals( $originalList ) );
98
99
		$list->detach( $one );
100
		$list->detach( $two );
101
102
		$list->attach( new HashableObject( 1 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
103
		$list->attach( new HashableObject( 1 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
104
105
		$this->assertEquals(
106
			$newHash,
107
			$list->getValueHash(),
108
			'The hash of HashableObjectStorage with different instances of the same elemnets should be the same'
109
		);
110
111
		$this->assertTrue( $list->equals( $originalList ) );
112
	}
113
114
	public function testEquals() {
115
		$list = new HashableObjectStorage();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\HashableObjectStorage has been deprecated with message: since 4.4, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
116
117
		$this->assertTrue( $list->equals( $list ), 'Empty list should be equal to itself' );
118
119
		$newList = clone $list;
120
121
		$this->assertTrue( $list->equals( $newList ), 'Empty list should be equal to a clone of itself' );
122
123
		$newList->attach( new HashableObject( 1 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
124
125
		$this->assertFalse( $list->equals( $newList ), 'Empty list should not be equal to a list with an element' );
126
127
		$list->attach( new HashableObject( 1 ) );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Fixtures\HashableObject has been deprecated with message: since 5.0, removal in 6.0 as per https://github.com/wmde/WikibaseDataModel/pull/498

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
128
129
		$this->assertTrue( $list->equals( $newList ), 'Two lists with the same element should be equal' );
130
	}
131
132
}
133