@@ -88,7 +88,7 @@ public function testHashStability() {
8888 $ hash = $ snak ->getHash ();
8989
9090 // @codingStandardsIgnoreStart
91- $ expected = sha1 ( 'C:41:"Wikibase\DataModel\Snak\PropertyValueSnak":53 :{a:2:{i:0;i:1 ;i:1;C:22:"DataValues\StringValue":1:{a}}} ' );
91+ $ expected = sha1 ( 'C:41:"Wikibase\DataModel\Snak\PropertyValueSnak":58 :{a:2:{i:0;s:2:"P1" ;i:1;C:22:"DataValues\StringValue":1:{a}}} ' );
9292 // @codingStandardsIgnoreEnd
9393 $ this ->assertSame ( $ expected , $ hash );
9494 }
@@ -121,15 +121,62 @@ public function notEqualsProvider() {
121121 ];
122122 }
123123
124- public function testSerialize () {
125- $ snak = new PropertyValueSnak ( new PropertyId ( 'P1 ' ), new StringValue ( 'a ' ) );
126- $ this ->assertSame ( 'a:2:{i:0;i:1;i:1;C:22:"DataValues\StringValue":1:{a}} ' , $ snak ->serialize () );
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 ' );
127151 }
128152
129- public function testUnserialize () {
153+ public function provideDataToUnserialize () {
154+ $ p2 = new PropertyId ( 'P2 ' );
155+ $ p2foo = new PropertyId ( 'foo:P2 ' );
156+ $ value = new StringValue ( 'b ' );
157+
158+ return [
159+ 'legacy ' => [
160+ new PropertyValueSnak ( $ p2 , $ value ),
161+ 'a:2:{i:0;i:2;i:1;C:22:"DataValues\StringValue":1:{b}} '
162+ ],
163+ 'current ' => [
164+ new PropertyValueSnak ( $ p2 , $ value ),
165+ 'a:2:{i:0;s:2:"P2";i:1;C:22:"DataValues\StringValue":1:{b}} '
166+ ],
167+ 'foreign ' => [
168+ new PropertyValueSnak ( $ p2foo , $ value ),
169+ 'a:2:{i:0;s:6:"foo:P2";i:1;C:22:"DataValues\StringValue":1:{b}} '
170+ ],
171+ ];
172+ }
173+
174+ /**
175+ * @dataProvider provideDataToUnserialize
176+ */
177+ public function testUnserialize ( $ expected , $ serialized ) {
130178 $ snak = new PropertyValueSnak ( new PropertyId ( 'P1 ' ), new StringValue ( 'a ' ) );
131- $ snak ->unserialize ( 'a:2:{i:0;i:2;i:1;C:22:"DataValues\StringValue":1:{b}} ' );
132- $ expected = new PropertyValueSnak ( new PropertyId ( 'P2 ' ), new StringValue ( 'b ' ) );
179+ $ snak ->unserialize ( $ serialized );
133180 $ this ->assertTrue ( $ snak ->equals ( $ expected ) );
134181 }
135182
0 commit comments