Exemplo n.º 1
0
 public function testReferenceJsons()
 {
     $first = TreeObject::createFrom(new JsonImport('{ "foo":{ "bar":"baz", "biz":"foo" }, "fiz":{ "foo":"baz" }, "bar":"baz", "baz":[ "foo", "bar" ] }'));
     $second = TreeObject::createFrom(new JsonImport('{ "foo":{ "bar":"baz1", "biz":"foo" }, "fiz":{ "foo":"baz" }, "bar":"baz", "baz":[ "foo1" ] }'));
     $diff = $this->comparator->diff($first, $second);
     $this->assertEquals('{"foo":{"bar":"baz1"},"baz":["foo1"]}', $diff->exportWith(new JsonExport()));
 }
Exemplo n.º 2
0
 public function testChangedObjectInSubTree()
 {
     $first = TreeObject::createFrom(new Provider(["a" => 1, "b" => ["c" => 2, "d" => 3]]));
     $second = TreeObject::createFrom(new Provider(["a" => 1, "b" => ["c" => 2, "d" => ["e" => 4]]]));
     $this->assertEquals(["b" => ["d" => ["e" => 4]]], $this->comparator->diff($first, $second)->exportWith($this->exporter));
 }
Exemplo n.º 3
0
<?php

/**
 * Created by PhpStorm.
 * User: alexk
 * Date: 2/2/16
 * Time: 9:58 PM
 */
chdir(dirname(__DIR__));
require_once "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
use JsonDiff\ValueObject\Tree\Tree as TreeObject;
use JsonDiff\DataProvider\Json\Import as JsonProvider;
use JsonDiff\Comparator\Diff\Tree\Tree as Comparator;
use JsonDiff\DataProvider\Json\Export as JsonExporter;
$first = TreeObject::createFrom(new JsonProvider('{ "foo":{ "bar":"baz", "biz":"foo" }, "fiz":{ "foo":"baz" }, "bar":"baz", "baz":[ "foo", "bar" ] }'));
$second = TreeObject::createFrom(new JsonProvider('{ "foo":{ "bar":"baz1", "biz":"foo" }, "fiz":{ "foo":"baz" }, "bar":"baz", "baz":[ "foo1" ] }'));
$comparator = new Comparator();
$diff = $comparator->diff($first, $second);
$jsonExporter = new JsonExporter();
echo $first->exportWith($jsonExporter), PHP_EOL;
echo $second->exportWith($jsonExporter), PHP_EOL;
echo $diff->exportWith($jsonExporter), PHP_EOL;