1515 it ('works with JsonRepairer class directly ' , function (): void {
1616 $ repairer = new JsonRepairer ("{'key': 'value'} " );
1717 $ result = $ repairer ->repair ();
18- expect (json_validate ($ result ))->toBeTrue ();
19- expect (json_decode ($ result , true )['key ' ])->toBe ('value ' );
18+ expect (json_validate ($ result ))->toBeTrue ()
19+ ->and (json_decode ($ result , true )['key ' ])
20+ ->toBe ('value ' );
2021 });
2122
2223 it ('can decode repaired JSON ' , function (): void {
2324 $ repairer = new JsonRepairer ("{'key': 'value', 'number': 123} " );
2425 $ decoded = $ repairer ->decode ();
2526
26- expect ($ decoded )->toBeArray ();
27- expect ($ decoded ['key ' ])->toBe ('value ' );
28- expect ($ decoded ['number ' ])->toBe (123 );
27+ expect ($ decoded )->toBeArray ()
28+ ->toMatchArray ([
29+ 'key ' => 'value ' ,
30+ 'number ' => 123 ,
31+ ]);
2932 });
3033
3134 it ('can use json_repair_decode helper function ' , function (): void {
3235 $ decoded = json_repair_decode ("{'key': 'value', 'number': 123} " );
3336
34- expect ($ decoded )->toBeArray ();
35- expect ($ decoded ['key ' ])->toBe ('value ' );
36- expect ($ decoded ['number ' ])->toBe (123 );
37+ expect ($ decoded )->toBeArray ()
38+ ->toMatchArray ([
39+ 'key ' => 'value ' ,
40+ 'number ' => 123 ,
41+ ]);
3742 });
3843
3944 it ('works with JsonRepairer class directly with omitEmptyValues ' , function (): void {
5459
5560 it ('works with json_repair_decode with new options ' , function (): void {
5661 $ decoded = json_repair_decode ('{"key": } ' , omitEmptyValues: true );
57- expect ($ decoded )->toBeArray ();
58- expect ( $ decoded ) ->toBe ([]);
62+ expect ($ decoded )->toBeArray ()
63+ ->toBe ([]);
5964 });
6065});
6166
6469 $ repairer = new JsonRepairer ("{'key': 'value'} " );
6570 $ repairResult = $ repairer ->repairWithDetails ();
6671
67- expect ($ repairResult ->wasAlreadyValid )->toBeFalse ();
68- expect ($ repairResult ->json )->toBe ('{"key": "value"} ' );
69- expect ($ repairResult ->fixes )->toContain ('Starting JSON repair ' );
72+ expect ($ repairResult ->wasAlreadyValid )->toBeFalse ()
73+ ->and ($ repairResult ->json )
74+ ->toBe ('{"key": "value"} ' )
75+ ->and ($ repairResult ->fixes )
76+ ->toContain ('Starting JSON repair ' );
7077 });
7178
7279 it ('marks valid JSON as already valid ' , function (): void {
7380 $ repairResult = (new JsonRepairer ('{"key": "value"} ' ))->repairWithDetails ();
7481
75- expect ($ repairResult ->wasAlreadyValid )->toBeTrue ();
76- expect ($ repairResult ->json )->toBe ('{"key": "value"} ' );
77- expect ($ repairResult ->fixes )->toContain ('JSON is already valid, returning as-is ' );
82+ expect ($ repairResult ->wasAlreadyValid )->toBeTrue ()
83+ ->and ($ repairResult ->json )
84+ ->toBe ('{"key": "value"} ' )
85+ ->and ($ repairResult ->fixes )
86+ ->toContain ('JSON is already valid, returning as-is ' );
7887 });
7988});
8089
8392 $ repairer = new JsonRepairer ('{"a":1}{"b":2} ' );
8493 $ results = $ repairer ->repairAll ();
8594
86- expect ($ results )->toHaveCount (2 );
87- expect (json_decode ($ results [0 ], true ))->toBe ([
88- 'a ' => 1 ,
89- ]);
90- expect (json_decode ($ results [1 ], true ))->toBe ([
91- 'b ' => 2 ,
92- ]);
95+ expect ($ results )->toHaveCount (2 )
96+ ->and (json_decode ($ results [0 ], true ))
97+ ->toBe ([
98+ 'a ' => 1 ,
99+ ])
100+ ->and (json_decode ($ results [1 ], true ))
101+ ->toBe ([
102+ 'b ' => 2 ,
103+ ]);
93104 });
94105
95106 it ('repairs NDJSON lines ' , function (): void {
96107 $ repairer = new JsonRepairer ("{'a':1} \n{'b':2} " );
97108 $ results = $ repairer ->repairAll ();
98109
99- expect ($ results )->toHaveCount (2 );
100- expect (json_decode ($ results [0 ], true ))->toBe ([
101- 'a ' => 1 ,
102- ]);
103- expect (json_decode ($ results [1 ], true ))->toBe ([
104- 'b ' => 2 ,
105- ]);
110+ expect ($ results )->toHaveCount (2 )
111+ ->and (json_decode ($ results [0 ], true ))
112+ ->toBe ([
113+ 'a ' => 1 ,
114+ ])
115+ ->and (json_decode ($ results [1 ], true ))
116+ ->toBe ([
117+ 'b ' => 2 ,
118+ ]);
106119 });
107120
108121 it ('repairs top-level values despite leading stray closing brackets ' , function (): void {
109122 $ repairer = new JsonRepairer ('}{"a":1}{"b":2} ' );
110123 $ results = $ repairer ->repairAll ();
111124
112- expect ($ results )->toHaveCount (2 );
113- expect (json_decode ($ results [0 ], true ))->toBe ([
114- 'a ' => 1 ,
115- ]);
116- expect (json_decode ($ results [1 ], true ))->toBe ([
117- 'b ' => 2 ,
118- ]);
125+ expect ($ results )->toHaveCount (2 )
126+ ->and (json_decode ($ results [0 ], true ))
127+ ->toBe ([
128+ 'a ' => 1 ,
129+ ])
130+ ->and (json_decode ($ results [1 ], true ))
131+ ->toBe ([
132+ 'b ' => 2 ,
133+ ]);
119134 });
120135});
121136
142157 $ repairer = new JsonRepairer ('{a: 1, b: 2, a: 3} ' , duplicateKeyPolicy: DuplicateKeyPolicy::KeepFirst);
143158 $ result = $ repairer ->repair ();
144159
145- expect (json_validate ($ result ))->toBeTrue ();
146- expect (json_decode ($ result , true ))->toBe ([
147- 'a ' => 1 ,
148- 'b ' => 2 ,
149- ]);
160+ expect (json_validate ($ result ))->toBeTrue ()
161+ ->and (json_decode ($ result , true ))
162+ ->toBe ([
163+ 'a ' => 1 ,
164+ 'b ' => 2 ,
165+ ]);
150166 });
151167
152168 it ('keeps last non-adjacent duplicate key without dropping intervening keys ' , function (): void {
153169 $ repairer = new JsonRepairer ('{a: 1, b: 2, a: 3} ' , duplicateKeyPolicy: DuplicateKeyPolicy::KeepLast);
154170 $ result = $ repairer ->repair ();
155171
156- expect (json_validate ($ result ))->toBeTrue ();
157- expect (json_decode ($ result , true ))->toBe ([
158- 'b ' => 2 ,
159- 'a ' => 3 ,
160- ]);
172+ expect (json_validate ($ result ))->toBeTrue ()
173+ ->and (json_decode ($ result , true ))
174+ ->toBe ([
175+ 'b ' => 2 ,
176+ 'a ' => 3 ,
177+ ]);
161178 });
162179
163180 it ('keeps last across multiple non-adjacent duplicates ' , function (): void {
164181 $ repairer = new JsonRepairer ('{a: 1, b: 2, a: 3, b: 4} ' , duplicateKeyPolicy: DuplicateKeyPolicy::KeepLast);
165182 $ result = $ repairer ->repair ();
166183
167- expect (json_validate ($ result ))->toBeTrue ();
168- expect (json_decode ($ result , true ))->toBe ([
169- 'a ' => 3 ,
170- 'b ' => 4 ,
171- ]);
184+ expect (json_validate ($ result ))->toBeTrue ()
185+ ->and (json_decode ($ result , true ))
186+ ->toBe ([
187+ 'a ' => 3 ,
188+ 'b ' => 4 ,
189+ ]);
172190 });
173191
174192 it ('does not corrupt large integers when keep-last is enabled ' , function (): void {
178196 );
179197 $ result = $ repairer ->repair ();
180198
181- expect (json_validate ($ result ))->toBeTrue ();
182- expect ($ result )-> toContain ( ' 12345678901234567890 ' );
183- expect ( $ result )->not ->toContain ('e+ ' );
199+ expect (json_validate ($ result ))->toBeTrue ()
200+ -> and ($ result )
201+ -> toContain ( ' 12345678901234567890 ' )->not ->toContain ('e+ ' );
184202 });
185203
186204 it ('preserves large integers while still deduplicating with keep-last ' , function (): void {
190208 );
191209 $ result = $ repairer ->repair ();
192210
193- expect (json_validate ($ result ))->toBeTrue ();
194- expect ($ result )-> toContain ( ' 12345678901234567890 ' );
195- expect ( $ result )->not ->toContain ('e+ ' );
211+ expect (json_validate ($ result ))->toBeTrue ()
212+ -> and ($ result )
213+ -> toContain ( ' 12345678901234567890 ' )->not ->toContain ('e+ ' );
196214
197215 $ decoded = json_decode ($ result , true );
198216 expect ($ decoded ['a ' ])->toBe (2 );
205223 );
206224 $ result = $ repairer ->repair ();
207225
208- expect (json_validate ($ result ))->toBeTrue ();
209- expect (json_decode ($ result , true ))->toBe ([
210- 'a ' => 1 ,
211- 'z ' => 9 ,
212- ]);
226+ expect (json_validate ($ result ))->toBeTrue ()
227+ ->and (json_decode ($ result , true ))
228+ ->toBe ([
229+ 'a ' => 1 ,
230+ 'z ' => 9 ,
231+ ]);
213232 });
214233
215234 it (
@@ -221,11 +240,12 @@ function (): void {
221240 );
222241 $ result = $ repairer ->repair ();
223242
224- expect (json_validate ($ result ))->toBeTrue ();
225- expect (json_decode ($ result , true ))->toBe ([
226- 'a ' => 1 ,
227- 'z ' => 9 ,
228- ]);
243+ expect (json_validate ($ result ))->toBeTrue ()
244+ ->and (json_decode ($ result , true ))
245+ ->toBe ([
246+ 'a ' => 1 ,
247+ 'z ' => 9 ,
248+ ]);
229249 },
230250 );
231251});
0 commit comments