1111 */
1212class Issue6Test extends \PHPUnit_Framework_TestCase
1313{
14- public function testIssue6 ()
14+ public function testDefault ()
1515 {
1616 $ json1 = json_decode ('[{"name":"a"},{"name":"b"},{"name":"c"}] ' );
1717 $ json2 = json_decode ('[{"name":"b"}] ' );
@@ -37,7 +37,7 @@ public function testIssue6()
3737 },
3838 {
3939 "op": "remove",
40- "path": "/2 "
40+ "path": "/1 "
4141 }
4242]
4343JSON
@@ -49,21 +49,42 @@ public function testIssue6()
4949 $ this ->assertEquals ($ json2 , $ json1a );
5050 }
5151
52+ public function testOriginal ()
53+ {
54+ $ originalJson = '[{"name":"a"},{"name":"b"},{"name":"c"}] ' ;
55+ $ newJson = '[{"name":"b"}] ' ;
56+ $ diff = new JsonDiff (json_decode ($ originalJson ), json_decode ($ newJson ));
57+
58+ $ patchJson = json_decode (json_encode ($ diff ->getPatch ()->jsonSerialize ()), true );
59+
60+ $ original = json_decode ($ originalJson );
61+ $ patch = JsonPatch::import ($ patchJson );
62+ $ patch ->apply ($ original );
63+ $ this ->assertEquals ($ original , json_decode ($ newJson ));
64+ }
65+
66+
67+ public function testDoubleInverseRemove ()
68+ {
69+ $ json1 = json_decode ('[{"name":"a"},{"name":"b"},{"name":"c"}] ' );
70+ $ json2 = json_decode ('[{"name":"b"}] ' );
71+
72+ $ patch = JsonPatch::import (json_decode ('[{"op":"remove","path":"/2"},{"op":"remove","path":"/0"}] ' ));
73+
74+ $ json1a = $ json1 ;
75+ $ patch ->apply ($ json1a );
76+ $ this ->assertEquals (json_encode ($ json2 ), json_encode ($ json1a ));
77+ }
5278
53- public function testIssue6Remove ()
79+ public function testDoubleRemove ()
5480 {
5581 $ json1 = json_decode ('[{"name":"a"},{"name":"b"},{"name":"c"}] ' );
5682 $ json2 = json_decode ('[{"name":"b"}] ' );
5783
58- $ patch = JsonPatch::import (json_decode ('[{"op":"remove","path":"/0"},{"op":"remove","path":"/2 "}] ' ));
84+ $ patch = JsonPatch::import (json_decode ('[{"op":"remove","path":"/0"},{"op":"remove","path":"/1 "}] ' ));
5985
6086 $ json1a = $ json1 ;
6187 $ patch ->apply ($ json1a );
6288 $ this ->assertEquals (json_encode ($ json2 ), json_encode ($ json1a ));
63- /*
64- Failed asserting that two strings are equal.
65- Expected :'[{"name":"b"}]'
66- Actual :'{"1":{"name":"b"}}'
67- */
6889 }
6990}
0 commit comments