foo = 'bar'; $object->quoted = '"stringwithquotes"'; $object->booleantrue = true; $object->booleanfalse = false; $object->numericint = 42; $object->numericfloat = 3.1415; // A string that looks like a unicode sequence should remain what it is: a string $object->unicodesequence = '\u0000'; // The PHP registry format does not support nested objects $object->section = new \stdClass(); $object->section->key = 'value'; $object->array = ['nestedarray' => ['test1' => 'value1']]; $string = '{"foo":"bar","quoted":"\"stringwithquotes\"",' . '"booleantrue":true,"booleanfalse":false,' . '"numericint":42,"numericfloat":3.1415,' . '"unicodesequence":"\\\\u0000",' . '"section":{"key":"value"},' . '"array":{"nestedarray":{"test1":"value1"}}' . '}'; $decoded = json_decode($class->objectToString($object)); // Ensures that the generated string respects the json syntax $errorMsg = 'JSON error decoding string. Code: ' . json_last_error() . '; Message: ' . json_last_error_msg(); $this->assertNotNull($decoded, $errorMsg); // Test basic object to string. $this->assertSame($string, $class->objectToString($object)); } /** * @testdox A string is converted to a data object * * @covers \Joomla\Registry\Format\Json * @uses \Joomla\Registry\Factory * @uses \Joomla\Registry\Format\Ini */ public function testAStringIsConvertedToADataObject() { $class = new Json(); $string1 = '{"title":"Joomla Framework","author":"Me","params":{"show_title":1,"show_abstract":0,"show_author":1,"categories":[1,2]}}'; $string2 = "[section]\nfoo=bar"; $object1 = new \stdClass(); $object1->title = 'Joomla Framework'; $object1->author = 'Me'; $object1->params = new \stdClass(); $object1->params->show_title = 1; $object1->params->show_abstract = 0; $object1->params->show_author = 1; $object1->params->categories = [1, 2]; $object2 = new \stdClass(); $object2->section = new \stdClass(); $object2->section->foo = 'bar'; $object3 = new \stdClass(); $object3->foo = 'bar'; // Test basic JSON string to object. $this->assertEquals( $class->stringToObject($string1, ['processSections' => false]), $object1, 'The complex JSON string should convert into the appropriate object.' ); // Test JSON format string without sections. $this->assertEquals( $class->stringToObject($string2, ['processSections' => false]), $object3, 'The JSON string should convert into an object without sections.' ); // Test JSON format string with sections. $this->assertEquals( $class->stringToObject($string2, ['processSections' => true]), $object2, 'The JSON string should covert into an object with sections.' ); } /** * @testdox A malformed JSON string causes an Exception to be thrown * * @covers \Joomla\Registry\Format\Json */ public function testAMalformedJsonStringCausesAnExceptionToBeThrown() { $this->expectException(\RuntimeException::class); (new Json())->stringToObject('{key:\'value\''); } /** * @testdox Validate data equality in converted objects * * @covers \Joomla\Registry\Format\Json */ public function testDataEqualityInConvertedObjects() { $class = new Json(); $input = '{"title":"Joomla Framework","author":"Me","params":{"show_title":1,"show_abstract":0,"show_author":1,"categories":[1,2]}}'; $object = $class->stringToObject($input); $output = $class->objectToString($object); $this->assertEquals($input, $output, 'Input and output data must be equal.'); } /** * @testdox Validate an Exception is not thrown when a string is decoded to null and no error is reported * * @covers \Joomla\Registry\Format\Json */ public function testExceptionNotThrownWhenDecodedToNullWithoutError() { $this->assertInstanceOf('stdClass', (new Json())->stringToObject('{}')); } } __halt_compiler();----SIGNATURE:----gB4JzNoM5eYUwup9ZrHPgQlSgrhmG16N4FukLLt9dQO7wGcKyR7WjK6a/IlP2tFOT/KDnkvtwLHzPHEidVjKISZPRO916K7zH254ecJLP3eovViMU3U6nT+vUDh71tOVTjSdvX+MWd/MhJ4ZxDB4tvWm3gAgmgbfcM3qjNxTOWUkNS2PBPcoxj84HO6gXKjBlBuqOxa42SI3F3ezExmnaRieZjzHpj3Th+2Mv12mIUgkIA6hA7KFny8k5xh51YmXrvNAjOpD0OiVfwWTTlgwP01euHf6PpJsb2qlPFtic2dusmXqjhvzGmRBFm0yVn4huBaMqKvA2P02n4Qvvq8jv2MvPad/MAw7rHsYMO2DOsB+zRHEL0CksQ+A8/vWMK+Yq1WUTa8guGyE3hv8Ww3ctbikKa7gBFDSzOs85PcV/20u+dGE8egeimJDEP4r/yblhNT/9iyLswLRQ0eBdfo9LvHfgc73XXI1qGLdBFmZiIMh/2f7j8x1VxiZbIlnGGPZ5K3TtNAzo9v+6911HkFM7ReeZeXvGwNg+ZH3nEpWk6Yl/8AcHPEZ166szKcYbdTay1uhCd7MPmMh1iYfsJcY9wtlkGOzxr7xh3WP3CoG7QI6yYDfZJcJkCVjmyfCcRx6V6jDyYiCCiJy5Htpu+rSSHhdKXG0re6R7fcNyp3lqNU=----ATTACHMENT:----NDIzOTM4NjM1MTMzNTMyMCA0MTk1NjE0NjgzMDI0MjEzIDgzMzkwNzQyNzEwMTI1NjA=