File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ require_once '../../php7/src/diff-patch.php ' ;
3
+
4
+ // for all directories in ../data directory, run the test
5
+ $ dataDir = __DIR__ . '/../data ' ;
6
+ $ dirs = scandir ($ dataDir );
7
+ $ dirs = array_diff ($ dirs , array ('.. ' , '. ' ));
8
+
9
+ foreach ($ dirs as $ dir ) {
10
+ // write dir name, but keep the cursor at the same line
11
+ echo "Testing: $ dir ... " ;
12
+
13
+ $ file01 = $ dataDir . '/ ' . $ dir . '/01.json ' ;
14
+ $ file02 = $ dataDir . '/ ' . $ dir . '/02.json ' ;
15
+
16
+ // read file 01.json and 02.json from the directory
17
+ $ obj01 = json_decode (file_get_contents ($ file01 ), true );
18
+ $ obj02 = json_decode (file_get_contents ($ file02 ), true );
19
+
20
+ // diff obj01 and obj02 and create a diffData object
21
+ $ diffData = diff ($ obj01 , $ obj02 );
22
+
23
+ // apply diffData to obj01 and create a new object
24
+ $ patched_obj01 = patch ($ obj01 , $ diffData );
25
+
26
+ // check if patched_obj01 is equal to obj02
27
+ if (json_encode ($ patched_obj01 ) !== json_encode ($ obj02 )) {
28
+ echo "FAILED \n" ;
29
+ } else {
30
+ echo "OK \n" ;
31
+ }
32
+ }
33
+ ?>
You can’t perform that action at this time.
0 commit comments