1 | <?php |
||
30 | class PropertyValueSnakTest extends PHPUnit_Framework_TestCase { |
||
31 | |||
32 | /** |
||
33 | * @dataProvider validConstructorArgumentsProvider |
||
34 | */ |
||
35 | public function testConstructor( $propertyId, DataValue $dataValue ) { |
||
39 | |||
40 | public function validConstructorArgumentsProvider() { |
||
47 | |||
48 | /** |
||
49 | * @dataProvider invalidConstructorArgumentsProvider |
||
50 | * @expectedException InvalidArgumentException |
||
51 | */ |
||
52 | public function testGivenInvalidConstructorArguments_constructorThrowsException( |
||
53 | $propertyId, |
||
54 | DataValue $dataValue |
||
55 | ) { |
||
56 | new PropertyValueSnak( $propertyId, $dataValue ); |
||
57 | } |
||
58 | |||
59 | public function invalidConstructorArgumentsProvider() { |
||
69 | |||
70 | public function testGetPropertyId() { |
||
75 | |||
76 | public function testGetHash() { |
||
82 | |||
83 | /** |
||
84 | * This test is a safeguard to make sure hashes are not changed unintentionally. |
||
85 | */ |
||
86 | public function testHashStability() { |
||
95 | |||
96 | public function testEquals() { |
||
102 | |||
103 | /** |
||
104 | * @dataProvider notEqualsProvider |
||
105 | */ |
||
106 | public function testGivenDifferentSnaks_EqualsReturnsFalse( Snak $snak1, Snak $snak2 ) { |
||
110 | |||
111 | public function notEqualsProvider() { |
||
123 | |||
124 | public function provideDataToSerialize() { |
||
125 | $p2 = new PropertyId( 'P2' ); |
||
126 | $p2foo = new PropertyId( 'foo:P2' ); |
||
127 | $value = new StringValue( 'b' ); |
||
128 | |||
129 | return [ |
||
130 | 'string' => [ |
||
131 | 'a:2:{i:0;s:2:"P2";i:1;C:22:"DataValues\StringValue":1:{b}}', |
||
132 | new PropertyValueSnak( $p2, $value ), |
||
133 | ], |
||
134 | 'foreign' => [ |
||
135 | 'a:2:{i:0;s:6:"foo:P2";i:1;C:22:"DataValues\StringValue":1:{b}}', |
||
136 | new PropertyValueSnak( $p2foo, $value ), |
||
137 | ], |
||
138 | ]; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @dataProvider provideDataToSerialize |
||
143 | */ |
||
144 | public function testSerialize( $expected, Snak $snak ) { |
||
145 | $serialized = $snak->serialize(); |
||
146 | $this->assertSame( $expected, $serialized ); |
||
147 | |||
148 | $snak2 = new PropertyValueSnak( new PropertyId( 'P1' ), new StringValue( 'a' ) ); |
||
149 | $snak2->unserialize( $serialized ); |
||
150 | $this->assertTrue( $snak->equals( $snak2 ), 'round trip' ); |
||
151 | } |
||
152 | |||
153 | public function provideDataToUnserialize() { |
||
173 | |||
174 | /** |
||
175 | * @dataProvider provideDataToUnserialize |
||
176 | */ |
||
177 | public function testUnserialize( $expected, $serialized ) { |
||
182 | |||
183 | public function testGetDataValue() { |
||
189 | |||
190 | } |
||
191 |