diff options
Diffstat (limited to 'MLEB/Translate/tests/phpunit/mocks/json/MockJsonUnserializableSubClass.php')
-rw-r--r-- | MLEB/Translate/tests/phpunit/mocks/json/MockJsonUnserializableSubClass.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/MLEB/Translate/tests/phpunit/mocks/json/MockJsonUnserializableSubClass.php b/MLEB/Translate/tests/phpunit/mocks/json/MockJsonUnserializableSubClass.php new file mode 100644 index 00000000..0170c536 --- /dev/null +++ b/MLEB/Translate/tests/phpunit/mocks/json/MockJsonUnserializableSubClass.php @@ -0,0 +1,42 @@ +<?php +declare( strict_types = 1 ); + +use MediaWiki\Extension\Translate\Utilities\Json\JsonUnserializableTrait; + +/** + * Testing class for JsonCodec unit tests. + * Remove once we need to support only MW >= 1.36 + * See Change-Id: I5433090ae8e2b3f2a4590cc404baf838025546ce + * + * @license GPL-2.0-or-later + */ +class MockJsonUnserializableSubClass extends MockJsonUnserializableSuperClass { + use JsonUnserializableTrait; + + /** @var string */ + private $subClassField; + + public function __construct( string $superClassFieldValue, string $subClassFieldValue ) { + parent::__construct( $superClassFieldValue ); + $this->subClassField = $subClassFieldValue; + } + + public function getSubClassField(): string { + return $this->subClassField; + } + + /** + * @param string[] $json + * @return self + */ + public static function newFromJsonArray( array $json ) { + return new self( $json['super_class_field'], $json['sub_class_field'] ); + } + + /** @return string[] */ + protected function toJsonArray(): array { + return parent::toJsonArray() + [ + 'sub_class_field' => $this->getSubClassField() + ]; + } +} |