Page MenuHomePhabricator

Why the type of values in mCategories in serialized data for ParserOutputTest::testDeserialization is int?
Open, Needs TriagePublic

Description

I met this question and created a separate change to test it: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/678420
Test result after I defined the parameter type of ParserOutput::addCategory() to string was failed:

ParserOutputTest::testDeserialization with data set "ParserOutput:withMetadata, deserialized from serialized, 1.31" ('unserialize', ParserOutput Object (...), Binary String: 0x4f3a31323a225...b4e3b7d)
mCategories
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
 Array &0 (
-    'category2' => '1'
-    'category1' => '2'
+    'category2' => 1
+    'category1' => 2
 )

See: https://integration.wikimedia.org/ci/job/mediawiki-quibble-vendor-mysql-php72-docker/43788/testReport/

Event Timeline

Func renamed this task from Why the type of mCategories in serialized data for ParserOutputTest::testDeserialization is int? to Why the type of values in mCategories in serialized data for ParserOutputTest::testDeserialization is int?.Apr 13 2021, 5:42 AM
Func updated the task description. (Show Details)
Func moved this task from Backlog to ParserOutput on the MediaWiki-Parser board.
Func added subscribers: Pchelolo, daniel.

@daniel and @Pchelolo: I found you are authors of files under \tests\phpunit\data\ParserCache, could you please check this out? Thanks!

@daniel and @Pchelolo: I found you are authors of files under \tests\phpunit\data\ParserCache, could you please check this out? Thanks!

The integer sort keys come from ParserCacheSerializationTestCases.php:

		$parserOutputWithMetadata->addCategory( 'category2', 1 );
		$parserOutputWithMetadata->addCategory( 'category1', 2 );

I guess this test data is just wrong, I see no reason for them to be integers. Though the method doesn't document any type, so I suppose until now, this was allowd.

I'll have to take a close took to remind myself how to correctly fix the serialization backwards compatibility test. Old serialized data can in fact contain integers here, the test reports the fact that the type changes unexpectedly during deserialization. We'd have to somehow tell the test that this is OK.

This comment was removed by daniel.

Maybe we should add more comments to define parameter type and provide document for ParserOutput so that phan and other CI tests can take part in.