Skip to content

Commit a19f5d7

Browse files
committed
Add: test_suite.php in php7 dir
1 parent 417d518 commit a19f5d7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/php7/test_suite.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
?>

0 commit comments

Comments
 (0)