* @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:----dZfU762XzpRC61OHoxdAd3Mz6kLNT72s0zHSixC7OC8tr8ca0TeNqWo0z5ozCRVNGkeWomOkoQfIhmOzT5iiRYq5/nRHzQ2a1nBLFzTlo/DumFT4VFPMOwc/qCvzcyaZZF5m0NKT6raUQ889mG0QdpDaLjxpzduRVkPc76vLippR6YLN59GqeroYvla9ZI7E/i2pWJ6MkTBhpdE5ZsDE89RAcQfo2QwfbU/eCo4bgT4lI5lN8Varn149XzkG6MTR/32V5yGtpTMTwuTbePRhNMppsWWhppp6T9ry86b5H9XPpmmRhi5Td7ZdIrzkIFHLvIHKlot9RGk5K+6QrKuX2JLl76RwD0dm70otbOP60J+WG/2i4teW5+/vPfG1Oq8cj3vkckd17U/7vAwlqy1tMXeN0Tc0mOhoeCHpbE/QzshcZeL95vOZo7Slu8GhKgzJOhB6dqH1fgKTRYyPCchtB9e6sGWMisjaEhU+BcCGUNuAjvdtCZOqdWNDctJqvXuOXxb9uO0JJSi8Ua6RcPhgAMPwLwjVmkX6iPTC8Ynd2pGVtuMnriAS+QuiloVVoeKyfvAcSOvnhY0/EGX/iOtUhS1rVFFL9laWKDa2NAQT/gvK9FNR4/+pjV2KJZ35k4zV+6DiNzFCZ7u76MsF4xoISeGKCh3wyWy63nsmhxicSTI=----ATTACHMENT:----NzEwNjEyMjgxNTg0NTUyMyAyMzA5NDgwMjAxNzU1MDM3IDUzMDQ2OTgwMzM2NjE4NzE=