Skip to content

Commit 30f6106

Browse files
lucaswerkmeistermanicki
authored andcommitted
Restore "EntityId: Hard-deprecate Serializable methods"
This reverts change I26ebf9069a (commit 680ec4eafc), restoring change Id36b2aebd6 (commit 1af704088a); the deprecation warnings we saw in production should have been fixed by WikibaseMediaInfo change Ifd87f4c303 (commit 65e2df926f). Bug: T345856 Change-Id: I189f95cd6a11a2e4a41bc1edd2dcb41a698e0d02
1 parent 4f02fa4 commit 30f6106

7 files changed

Lines changed: 24 additions & 5 deletions

File tree

RELEASE-NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Removed support for calling `Statement::addNewReference()` and `StatementList` constructor with a
66
single array argument, which was deprecated in `Version 9.6.0 (2021-03-31)`. These should now be
77
called with a variadic argument list.
8-
* Added `__serialize()` and `__unserialize()` methods to the `EntityId` interface.
8+
* Added `__serialize()` and `__unserialize()` methods to the `EntityId` interface,
9+
and deprecated the `serialize()` and `unserialize()` methods.
910
* Added native type hints to the `Statement` and `StatementList` classes
1011
* Added `strict_types=1` to `Statement.php`, `StatementList.php`, and related test files
1112
* Removed support for repository names in entity IDs (e.g. `foo:Q1234`)

src/Entity/ItemId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function __serialize(): array {
7171
* @return string
7272
*/
7373
public function serialize() {
74+
wfDeprecated( __METHOD__, '1.41' );
7475
return $this->serialization;
7576
}
7677

@@ -84,6 +85,7 @@ public function __unserialize( array $data ): void {
8485
* @param string $serialized
8586
*/
8687
public function unserialize( $serialized ) {
88+
wfDeprecated( __METHOD__, '1.41' );
8789
$array = json_decode( $serialized );
8890
$this->serialization = is_array( $array ) ? $array[1] : $serialized;
8991
$this->serialization = $this->serialization ?? '';

src/Entity/NumericPropertyId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function __serialize(): array {
6565
* @return string
6666
*/
6767
public function serialize() {
68+
wfDeprecated( __METHOD__, '1.41' );
6869
return $this->serialization;
6970
}
7071

@@ -78,6 +79,7 @@ public function __unserialize( array $data ): void {
7879
* @param string $serialized
7980
*/
8081
public function unserialize( $serialized ) {
82+
wfDeprecated( __METHOD__, '1.41' );
8183
$array = json_decode( $serialized );
8284
$this->serialization = is_array( $array ) ? $array[1] : $serialized;
8385
$this->serialization = $this->serialization ?? '';

tests/unit/Entity/EntityIdTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wikibase\DataModel\Tests\Entity;
44

55
use InvalidArgumentException;
6+
use MediaWikiUnitTestCase;
67
use ReflectionClass;
78
use Wikibase\DataModel\Entity\EntityId;
89
use Wikibase\DataModel\Entity\ItemId;
@@ -21,7 +22,7 @@
2122
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
2223
* @author John Erling Blad < jeblad@gmail.com >
2324
*/
24-
class EntityIdTest extends \PHPUnit\Framework\TestCase {
25+
class EntityIdTest extends MediaWikiUnitTestCase {
2526

2627
public static function instanceProvider() {
2728
$ids = [];
@@ -73,6 +74,9 @@ public static function deserializationCompatibilityProvider(): array {
7374
* @dataProvider deserializationCompatibilityProvider
7475
*/
7576
public function testDeserializationCompatibility( $expected, $serialization ) {
77+
if ( str_starts_with( $serialization, 'C:' ) ) {
78+
$this->expectDeprecationAndContinue( '/::unserialize/' );
79+
}
7680
$this->assertEquals(
7781
$expected,
7882
unserialize( $serialization )

tests/unit/Entity/EntityIdValueTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wikibase\DataModel\Tests\Entity;
44

55
use DataValues\IllegalValueException;
6+
use MediaWikiUnitTestCase;
67
use Wikibase\DataModel\Entity\EntityId;
78
use Wikibase\DataModel\Entity\EntityIdValue;
89
use Wikibase\DataModel\Entity\ItemId;
@@ -20,7 +21,7 @@
2021
* @author Thiemo Kreuz
2122
* @author Daniel Kinzler
2223
*/
23-
class EntityIdValueTest extends \PHPUnit\Framework\TestCase {
24+
class EntityIdValueTest extends MediaWikiUnitTestCase {
2425

2526
public function testCanConstruct() {
2627
$entityId = new ItemId( 'Q123' );
@@ -160,6 +161,9 @@ public static function provideDeserializationCompatibility() {
160161
* @param EntityIdValue $expected
161162
*/
162163
public function testDeserializationCompatibility( $serialized, EntityIdValue $expected ) {
164+
if ( str_contains( $serialized, 'C:32:"Wikibase\DataModel\Entity\ItemId"' ) ) {
165+
$this->expectDeprecationAndContinue( '/::unserialize/' );
166+
}
163167
$id = unserialize( $serialized );
164168

165169
$this->assertEquals( $expected, $id );

tests/unit/Entity/ItemIdTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wikibase\DataModel\Tests\Entity;
44

55
use InvalidArgumentException;
6+
use MediaWikiUnitTestCase;
67
use Wikibase\DataModel\Entity\ItemId;
78

89
/**
@@ -14,7 +15,7 @@
1415
* @license GPL-2.0-or-later
1516
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
1617
*/
17-
class ItemIdTest extends \PHPUnit\Framework\TestCase {
18+
class ItemIdTest extends MediaWikiUnitTestCase {
1819

1920
/**
2021
* @dataProvider idSerializationProvider
@@ -86,6 +87,7 @@ public function testGetEntityType() {
8687

8788
public function testSerialize() {
8889
$id = new ItemId( 'Q1' );
90+
$this->expectDeprecationAndContinue( '/ItemId::serialize/' );
8991
$this->assertSame( 'Q1', $id->serialize() );
9092
}
9193

@@ -94,6 +96,7 @@ public function testSerialize() {
9496
*/
9597
public function testUnserialize( $json, $expected ) {
9698
$id = new ItemId( 'Q1' );
99+
$this->expectDeprecationAndContinue( '/ItemId::unserialize/' );
97100
$id->unserialize( $json );
98101
$this->assertSame( $expected, $id->getSerialization() );
99102
}

tests/unit/Entity/NumericPropertyIdTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wikibase\DataModel\Tests\Entity;
44

55
use InvalidArgumentException;
6+
use MediaWikiUnitTestCase;
67
use Wikibase\DataModel\Entity\NumericPropertyId;
78

89
/**
@@ -13,7 +14,7 @@
1314
*
1415
* @license GPL-2.0-or-later
1516
*/
16-
class NumericPropertyIdTest extends \PHPUnit\Framework\TestCase {
17+
class NumericPropertyIdTest extends MediaWikiUnitTestCase {
1718

1819
/**
1920
* @dataProvider idSerializationProvider
@@ -85,6 +86,7 @@ public function testGetEntityType() {
8586

8687
public function testSerialize() {
8788
$id = new NumericPropertyId( 'P1' );
89+
$this->expectDeprecationAndContinue( '/NumericPropertyId::serialize/' );
8890
$this->assertSame( 'P1', $id->serialize() );
8991
}
9092

@@ -93,6 +95,7 @@ public function testSerialize() {
9395
*/
9496
public function testUnserialize( $json, $expected ) {
9597
$id = new NumericPropertyId( 'P1' );
98+
$this->expectDeprecationAndContinue( '/NumericPropertyId::unserialize/' );
9699
$id->unserialize( $json );
97100
$this->assertSame( $expected, $id->getSerialization() );
98101
}

0 commit comments

Comments
 (0)