| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\Tests\Message; |
| 4 |
|
| 5 |
use MediaWiki\Json\JsonCodec; |
| 6 |
use Wikimedia\Tests\SerializationTestTrait; |
| 7 |
|
| 8 |
trait MessageSerializationTestTrait { |
| 9 |
use SerializationTestTrait; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public static function getSerializedDataPath(): string { |
| 16 |
return __DIR__ . '/../../../../data/MessageValue'; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public static function getTestInstancesAndAssertions(): array { |
| 24 |
$className = self::getClassToTest(); |
| 25 |
return array_map( static function ( $test ) use ( $className ) { |
| 26 |
[ $args, $expected ] = $test; |
| 27 |
$obj = new $className( ...$args ); |
| 28 |
return [ |
| 29 |
'instance' => $obj, |
| 30 |
'assertions' => static function ( $testCase, $obj ) use ( $expected ) { |
| 31 |
$testCase->assertSame( $expected, $obj->dump() ); |
| 32 |
}, |
| 33 |
]; |
| 34 |
}, self::provideConstruct() ); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public static function getSupportedSerializationFormats(): array { |
| 42 |
$jsonCodec = new JsonCodec(); |
| 43 |
return [ [ |
| 44 |
'ext' => 'json', |
| 45 |
'serializer' => static function ( $obj ) use ( $jsonCodec ) { |
| 46 |
return $jsonCodec->serialize( $obj ); |
| 47 |
}, |
| 48 |
'deserializer' => static function ( $data ) use ( $jsonCodec ) { |
| 49 |
return $jsonCodec->deserialize( $data ); |
| 50 |
}, |
| 51 |
] ]; |
| 52 |
} |
| 53 |
} |