/** * @test */ public function parseMustReturnArray() { $expected = ['some' => 1, 'valid' => false, 'payloads' => [1, "10", 1.1, null, true]]; $json = new Json(); $parsed = $json->parse(json_encode($expected)); $this->assertEquals($expected, $parsed); }
/** * parse() should return true if $output is valid json */ public function test_parse_returnsSelf_ifOutputIsValid() { $output = '{"foo":"bar"}'; $response = new Json(); $this->assertTrue($response->parse($output)); $this->assertEquals(['foo' => 'bar'], $response->getData()); return; }
public function testParse() { $expected = [['name' => 'magento/module-module1', 'dependencies' => [['module' => 'magento/module-module2', 'type' => 'hard'], ['module' => 'magento/module-backend', 'type' => 'soft']]], ['name' => 'magento/module-module2', 'dependencies' => [['module' => 'magento/module-module3', 'type' => 'hard']]]]; $actual = $this->parser->parse(['files_for_parse' => [$this->fixtureDir . 'composer1.json', $this->fixtureDir . 'composer2.json']]); $this->assertEquals($expected, $actual); }
/** * @test * @expectedException \Json\Exception\Decoding * @expectedExceptionMessage JSON decode failed: Maximum stack depth exceeded (1) */ public function parseDepthError() { if (version_compare(PHP_VERSION, '5.3.0', '<')) { $this->markTestSkipped('PHP Version < 5.3.0'); } // Default max-depth=512 ( x > 512 -> JSON_ERROR_DEPTH ) $json = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'; $result = Json::parse($json); }
array_push($stack, $v); } break; case 'Object': $obj = []; for ($i = count($tokens) - 4; $i > 0; $i -= 4) { $k = $this->parseString($tokens[$i][1]); $v = array_pop($stack); $obj[$k] = $v; } array_push($stack, (object) array_reverse($obj, true)); break; case 'Array': $arr = []; for ($i = count($tokens) - 2; $i > 0; $i -= 2) { $v = array_pop($stack); $arr[] = $v; } array_push($stack, array_reverse($arr)); break; } }); return $stack[0]; } } $j = new Json(); var_dump($j->parse('{"abc":123,"B":["a","b","c"],"c":"\\u795e\\u4ed9"}')); var_dump($j->parse('{"a":{"V":1},"b":{},"c":[],"d":true}')); var_dump($j->parse('"abcde"')); var_dump($j->parse('null')); var_dump($j->parse('false'));