* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class DocumentTest extends TestCase { public function testGet() { $document = Document::fromFile(__DIR__ . '/test_a.json'); $this->assertEquals('bar', $document->get('/string')); $this->assertEquals(12, $document->get('/number')); $this->assertEquals(false, $document->get('/boolean')); $this->assertEquals(null, $document->get('/null')); $this->assertEquals(['foo'], $document->get('/array')); $this->assertEquals('foo', $document->get('/array/0')); $this->assertEquals([(object) ['foo' => 'bar']], $document->get('/arrayObject')); $this->assertEquals('bar', $document->get('/arrayObject/0/foo')); $this->assertEquals('bar', $document->get('/object/foo')); } public function testGetNotExists() { $this->expectException(\InvalidArgumentException::class); $document = Document::fromFile(__DIR__ . '/test_a.json'); $this->assertEquals(null, $document->get('/array/1')); } public function testEquals() { $docA = Document::fromFile(__DIR__ . '/test_a.json'); $docB = Document::fromFile(__DIR__ . '/test_b.json'); $this->assertFalse($docA->equals($docB)); $this->assertTrue($docA->equals($docA)); } public function testPatch() { $docA = Document::fromFile(__DIR__ . '/test_a.json'); $docA->patch([ (object) ['op' => 'add', 'path' => '/array/-', 'value' => 'bar'], (object) ['op' => 'add', 'path' => '/object/bar', 'value' => 'bar'], ]); $this->assertEquals(['foo', 'bar'], $docA->get('/array')); $this->assertEquals((object) ['foo' => 'bar', 'bar' => 'bar'], $docA->get('/object')); } public function testToString() { $docA = Document::fromFile(__DIR__ . '/test_a.json'); $expect = file_get_contents(__DIR__ . '/test_a.json'); $this->assertJsonStringEqualsJsonString($expect, $docA->toString()); } } __halt_compiler();----SIGNATURE:----rogX+0SMBICEaWh9Qw0D9P/i+NmYW92Cwd9NaQO1fsjdsP7imdTDj8Si/HOsnLbEpQyuUMTOVy31A+UStc1EmIvg7kP39vcic2Pk74CDvAi5+9QQGjEtelHiRuajP98Qbqlz5t7kx4x+Ztq+xXPormTu2JVlZzM/WbiWo8JucUMeMQ/ZvnkwJYVW+IkXjdPdxIagSnD4BTQ1Iqjqfgy7pfePPdISJGOXG2yspLwPLtAm3tocmUghtG2U76tqpnnvlBb5vVLSQdgl/aAv4wQyS50BnAmhofk02K4YIinjriteQsQm+/Dotb0E9sy6eLz/KDMCLyv7BoS7abmmshPUPaUrC2g0MOeXaAsUuyYZIUJFXgwQBWFl9jSNlBRrw+5SiMn3S4v3qECwFsaC94/z2sdtT4bSmBJXUoPSrLnqe4pzGN891UXE2i0imI64tNRe63jg+02xkGzKZqAAFVHWRxxG7gWTklDsdZSfYNgdcFDgEPkjxpa0PwdqipWIt0WVSAeUWjm5UIBBULT7PkE2s1N7OdjRALZFDuZcjjLZ703NevuYylktxTWkGxg86bg0OtRFDxx1LoD4SfDJELlrE/n6G6n6B8gf5moYYpr2930rxWZBajlH1V/rnaER68JHGZJ3SHsf4NNNAMgTOZY+gKBL1AyVbrFQmQLdmiLIDNE=----ATTACHMENT:----NTg3NTMzNDk2NzE5NDE2MyAxOTY2NDIwMjU4NDA2MDQxIDEyODQyNzQyMTcyMzkyMzg=