wiki.techinc.nl/tests/phpunit/mocks/GhostFieldTestClass.php
C. Scott Ananian 19ee8c4f91 Serialization test cases: fix filename after ParserOutput namespacing
The serialization test cases look for files based on the name of the
class they are testing.  After the namespacing of ParserOutput, they
were looking for files named like:
  1.42-MediaWiki\Parser\ParserOutput-binaryPageProperties.json

The embedded backslashes in these filenames would raise havoc on Windows
machines.  What's more, none of the existing ParserOutput tests will
actually be checked anymore because the filenames don't match up
with what is expected after namespacing.

Fix this by stripping the namespace from the classname when forming
the test file names.

When this is done, the tests cases for GhostFieldAccess begin running
again, revealing that they were broken when GhostFieldTestClass was
re-namespaced.  Add a class alias for the GhostFieldTestClass to fix
this.

Finally, PHP <= 8.1 does not deserialize private properties correctly
after a class is renamed and aliased, because the internal name of the
private property contains the "old" class name in the serialization.
Add a new ::restoreAliasedGhostField() method to the
GhostFieldAccessTrait to workaround this issue and restore proper
deserialization of ParserOutput.

Bug: T365060
Followup-To: I9c64a631b0b4e8e4fef8a72ee0f749d35f918052
Followup-To: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
Change-Id: I7bafe80cd36c2558517f474871148286350a4e76
2024-05-17 17:07:47 -04:00

31 lines
981 B
PHP

<?php
namespace Wikimedia\Tests\Reflection;
use Wikimedia\Reflection\GhostFieldAccessTrait;
use Wikimedia\Reflection\GhostFieldTestClass as OldGhostFieldTestClass;
/**
* This class used to contain a $privateField, $protectedField and $publicField.
* This is used to test that unserialized instances still have the values of
* these ghost fields and the values can be accessed with GhostFieldAccessTrait.
*
*/
#[\AllowDynamicProperties]
class GhostFieldTestClass {
use GhostFieldAccessTrait;
public function getPrivateField() {
return $this->getGhostFieldValue( 'privateField', OldGhostFieldTestClass::class );
}
public function getProtectedField() {
return $this->getGhostFieldValue( 'protectedField' );
}
public function getPublicField() {
return $this->getGhostFieldValue( 'publicField' );
}
}
// Do not delete this alias; it is needed for GhostFieldAccessTraitTest
class_alias( GhostFieldTestClass::class, 'Wikimedia\\Reflection\\GhostFieldTestClass' );