Do not compare byte-for-byte of serialized items in tests [php8.1]
PHP 8.1 changes the order of protected properties in the output of serialize(). Previously they were at the end of the serialized stream, now they are at the beginning. Given that serialization formats have multiple equivalent encodings, and there is no guarantee that they might not arbitrary change between versions in backwards compatible ways, I think we should not do byte for byte comparisons. Instead we should deserialize both and compare the resulting objects for equality. This should test what we want to know (That we can read serialized structures) well also being safe against compatible format changes. This fixes a number of failing ParserOutputTest::testSerialization on php 8.1. Bug: T313663 Change-Id: Ic7a08b436d65ab7492f343fa02281e245834aaea
This commit is contained in:
parent
7a64e989c9
commit
e219728857
1 changed files with 19 additions and 4 deletions
|
|
@ -80,17 +80,32 @@ trait SerializationTestTrait {
|
|||
|
||||
yield "{$className}:{$testCaseName}, " .
|
||||
"serialized with {$serializationFormat['ext']}" =>
|
||||
[ $serializationFormat['serializer'], $expected->data, $testInstance ];
|
||||
[
|
||||
$serializationFormat['serializer'],
|
||||
$serializationFormat['deserializer'],
|
||||
$expected->data,
|
||||
$testInstance
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the current master $serialized instances are equal to stored $expected instances.
|
||||
* Test that the current master $serialized instances are
|
||||
* equal to stored $expected instances.
|
||||
* Serialization formats might change in backwards compatible ways
|
||||
* (in particular, php 8.1 orders protected instance variables differently
|
||||
* than earlier php), so do the comparision on the deserialized version.
|
||||
* @dataProvider provideSerialization
|
||||
*/
|
||||
public function testSerialization( callable $serializer, string $expected, object $testInstance ) {
|
||||
$this->assertSame( $expected, $serializer( $testInstance ) );
|
||||
public function testSerialization( callable $serializer, callable $deserializer, string $expected, object $testInstance ) {
|
||||
$serTestInstance = $serializer( $testInstance );
|
||||
$deserExpected = $deserializer( $expected );
|
||||
$this->assertNotEmpty( $deserExpected );
|
||||
$deserTestInstance = $deserializer( $serTestInstance );
|
||||
$this->assertNotEmpty( $deserTestInstance );
|
||||
|
||||
$this->validateObjectEquality( $deserExpected, $deserTestInstance );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue