jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/336835 )

Change subject: Simplify LexemeId serialization
......................................................................


Simplify LexemeId serialization

This is not a braking change because this component is not in
production anyway.

Change-Id: I66f1851864fb628bd6c3d600269cca199e4ade47
---
M src/DataModel/LexemeId.php
M tests/phpunit/composer/DataModel/LexemeIdTest.php
2 files changed, 17 insertions(+), 10 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  Aleksey Bekh-Ivanov (WMDE): Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/src/DataModel/LexemeId.php b/src/DataModel/LexemeId.php
index a50700d..3f3261c 100644
--- a/src/DataModel/LexemeId.php
+++ b/src/DataModel/LexemeId.php
@@ -54,7 +54,7 @@
         * @return string
         */
        public function serialize() {
-               return json_encode( [ 'lexeme', $this->serialization ] );
+               return $this->serialization;
        }
 
        /**
@@ -63,7 +63,7 @@
         * @param string $serialized
         */
        public function unserialize( $serialized ) {
-               list( , $this->serialization ) = json_decode( $serialized );
+               $this->serialization = $serialized;
        }
 
        /**
diff --git a/tests/phpunit/composer/DataModel/LexemeIdTest.php 
b/tests/phpunit/composer/DataModel/LexemeIdTest.php
index 93d5052..1a6baf4 100644
--- a/tests/phpunit/composer/DataModel/LexemeIdTest.php
+++ b/tests/phpunit/composer/DataModel/LexemeIdTest.php
@@ -23,6 +23,14 @@
                $this->assertSame( $normalizedSerialization, 
$id->getSerialization() );
        }
 
+       /**
+        * @dataProvider idSerializationProvider
+        */
+       public function testSerializationWorksProperly( $serialization ) {
+               $id = new LexemeId( $serialization );
+               $this->assertEquals( $id, unserialize( serialize( $id ) ) );
+       }
+
        public function idSerializationProvider() {
                return [
                        [ 'l1', 'L1' ],
@@ -74,7 +82,7 @@
 
        public function testSerialize() {
                $id = new LexemeId( 'L1' );
-               $this->assertSame( '["lexeme","L1"]', $id->serialize() );
+               $this->assertSame( 'L1', $id->serialize() );
        }
 
        /**
@@ -88,15 +96,14 @@
 
        public function serializationProvider() {
                return [
-                       [ '["lexeme","L2"]', 'L2' ],
+                       [ 'L2', 'L2' ],
 
                        // All these cases are kind of an injection vector and 
allow constructing invalid ids.
-                       [ '["string","L2"]', 'L2' ],
-                       [ '["","string"]', 'string' ],
-                       [ '["",""]', '' ],
-                       [ '["",2]', 2 ],
-                       [ '["",null]', null ],
-                       [ '', null ],
+                       [ 'L2', 'L2' ],
+                       [ 'string', 'string' ],
+                       [ '', '' ],
+                       [ 2, 2 ],
+                       [ null, null ],
                ];
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/336835
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I66f1851864fb628bd6c3d600269cca199e4ade47
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to