2020-11-05 17:04:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Wikimedia\Tests\Reflection;
|
|
|
|
|
|
|
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
|
use Wikimedia\Reflection\GhostFieldTestClass;
|
|
|
|
|
use Wikimedia\Tests\SerializationTestUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \Wikimedia\Reflection\GhostFieldAccessTrait
|
|
|
|
|
* @package Wikimedia\Tests\Reflection
|
|
|
|
|
*/
|
|
|
|
|
class GhostFieldAccessTraitTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
|
|
protected function setUp() : void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function provideUnserializedInstances( string $testCaseName ) {
|
2020-11-12 04:53:01 +00:00
|
|
|
// Not using the trait since we only need deserialization tests.
|
2020-11-05 17:04:37 +00:00
|
|
|
$serializationTestUtils = new SerializationTestUtils(
|
2020-11-12 04:53:01 +00:00
|
|
|
__DIR__ . '/../../../data/GhostFieldAccess',
|
2020-11-05 17:04:37 +00:00
|
|
|
[],
|
|
|
|
|
'serialized',
|
|
|
|
|
'serialize',
|
|
|
|
|
'unserialize'
|
|
|
|
|
);
|
|
|
|
|
$instances = $serializationTestUtils
|
|
|
|
|
->getDeserializedInstancesForTestCase( 'GhostFieldTestClass', $testCaseName );
|
|
|
|
|
foreach ( $instances as $instance ) {
|
|
|
|
|
yield "{$instance->version}" => [ $instance->object ];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideUnserializedInstancesWithValues() {
|
|
|
|
|
return $this->provideUnserializedInstances( 'withValues' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideUnserializedInstancesWithValues
|
|
|
|
|
* @param GhostFieldTestClass $instance
|
|
|
|
|
*/
|
|
|
|
|
public function testUnserializedWithValues( GhostFieldTestClass $instance ) {
|
|
|
|
|
$this->assertSame( 'private_value', $instance->getPrivateField() );
|
|
|
|
|
$this->assertSame( 'protected_value', $instance->getProtectedField() );
|
|
|
|
|
$this->assertSame( 'public_value', $instance->getPublicField() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideUnserializedInstancesWithNulls() {
|
|
|
|
|
return $this->provideUnserializedInstances( 'withNulls' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideUnserializedInstancesWithNulls
|
|
|
|
|
* @param GhostFieldTestClass $instance
|
|
|
|
|
*/
|
|
|
|
|
public function testUnserializedWithNulls( GhostFieldTestClass $instance ) {
|
|
|
|
|
$this->assertNull( $instance->getPrivateField() );
|
|
|
|
|
$this->assertNull( $instance->getProtectedField() );
|
|
|
|
|
$this->assertNull( $instance->getPublicField() );
|
|
|
|
|
}
|
|
|
|
|
}
|