| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\Tests\Reflection; |
| 4 |
|
| 5 |
use MediaWikiUnitTestCase; |
| 6 |
use Wikimedia\Tests\SerializationTestUtils; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class GhostFieldAccessTraitTest extends MediaWikiUnitTestCase { |
| 12 |
|
| 13 |
private static function provideUnserializedInstances( string $testCaseName ) { |
| 14 |
|
| 15 |
$serializationTestUtils = new SerializationTestUtils( |
| 16 |
__DIR__ . '/../../../data/GhostFieldAccess', |
| 17 |
[], |
| 18 |
'serialized', |
| 19 |
'serialize', |
| 20 |
'unserialize' |
| 21 |
); |
| 22 |
$instances = $serializationTestUtils |
| 23 |
->getDeserializedInstancesForTestCase( GhostFieldTestClass::class, $testCaseName ); |
| 24 |
foreach ( $instances as $instance ) { |
| 25 |
yield "{$instance->version}" => [ $instance->object ]; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
public function provideUnserializedInstancesWithValues() { |
| 30 |
return $this->provideUnserializedInstances( 'withValues' ); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function testUnserializedWithValues( GhostFieldTestClass $instance ) { |
| 37 |
$this->assertSame( 'private_value', $instance->getPrivateField() ); |
| 38 |
$this->assertSame( 'protected_value', $instance->getProtectedField() ); |
| 39 |
$this->assertSame( 'public_value', $instance->getPublicField() ); |
| 40 |
} |
| 41 |
|
| 42 |
public function provideUnserializedInstancesWithNulls() { |
| 43 |
return $this->provideUnserializedInstances( 'withNulls' ); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function testUnserializedWithNulls( GhostFieldTestClass $instance ) { |
| 50 |
$this->assertNull( $instance->getPrivateField() ); |
| 51 |
$this->assertNull( $instance->getProtectedField() ); |
| 52 |
$this->assertNull( $instance->getPublicField() ); |
| 53 |
} |
| 54 |
} |