1
+ <?php
2
+
3
+ namespace Swaggest \JsonDiff \Tests ;
4
+
5
+
6
+ use Swaggest \JsonDiff \JsonValueReplace ;
7
+
8
+ class ReplaceTest extends \PHPUnit_Framework_TestCase
9
+ {
10
+ public function testReplace ()
11
+ {
12
+ $ data = json_decode (<<<JSON
13
+ {
14
+ "data": [
15
+ {"a":"b","c":"d"},
16
+ {"c":"d", "a":"b"},
17
+ {"c":"d"}
18
+ ],
19
+ "o":{"a":"b","c":"d"}
20
+ }
21
+ JSON
22
+ );
23
+ $ replace = new JsonValueReplace (
24
+ json_decode ('{"a":"b","c":"d"} ' ),
25
+ json_decode ('{"a":"b","c":"d","e":"f"} ' )
26
+ );
27
+
28
+ $ result = $ replace ->process ($ data );
29
+ $ expected = json_decode (<<<JSON
30
+ {
31
+ "data": [
32
+ {"a":"b","c":"d","e":"f"},
33
+ {"c":"d", "a":"b","e":"f"},
34
+ {"c":"d"}
35
+ ],
36
+ "o":{"a":"b","c":"d","e":"f"}
37
+ }
38
+ JSON
39
+ );
40
+
41
+ $ this ->assertEquals ($ expected , $ result );
42
+ }
43
+
44
+
45
+ public function testReplaceScalar ()
46
+ {
47
+ $ data = json_decode (<<<JSON
48
+ {
49
+ "data": [
50
+ {"a":"b","c":"d"},
51
+ {"c":"d", "a":"b"},
52
+ {"c":"d"}
53
+ ],
54
+ "o":{"a":"b","c":"d"}
55
+ }
56
+ JSON
57
+ );
58
+ $ replace = new JsonValueReplace ("b " , "B " );
59
+
60
+ $ result = $ replace ->process ($ data );
61
+ $ expected = json_decode (<<<JSON
62
+ {
63
+ "data": [
64
+ {"a":"B","c":"d"},
65
+ {"c":"d", "a":"B"},
66
+ {"c":"d"}
67
+ ],
68
+ "o":{"a":"B","c":"d"}
69
+ }
70
+ JSON
71
+ );
72
+
73
+ $ this ->assertEquals ($ expected , $ result );
74
+ }
75
+
76
+ }
0 commit comments