Skip to content

Commit 0be2b18

Browse files
committed
chore: Upgrade Pest
1 parent d0729fc commit 0be2b18

12 files changed

Lines changed: 312 additions & 213 deletions

‎composer.json‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
},
2424
"require-dev": {
2525
"colinodell/psr-testlogger": "^1.3",
26-
"pestphp/pest": "^4.1.4",
27-
"pestphp/pest-plugin-type-coverage": "^4.0.3",
26+
"pestphp/pest": "^5.0",
27+
"pestphp/pest-plugin-phpstan": "^5.0",
28+
"pestphp/pest-plugin-rector": "^5.0",
29+
"pestphp/pest-plugin-type-coverage": "^5.0",
2830
"phpbench/phpbench": "^1.4",
2931
"phpstan/phpstan": "^2.1.32",
3032
"phpstan/phpstan-strict-rules": "^2.0",
3133
"rector/rector": "^2.2",
32-
"symplify/easy-coding-standard": "^13.0"
34+
"symplify/easy-coding-standard": "~13.1.0"
3335
},
3436
"autoload": {
3537
"psr-4": {

‎phpstan.dist.neon‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
includes:
22
- vendor/phpstan/phpstan-strict-rules/rules.neon
3+
- vendor/pestphp/pest-plugin-phpstan/extension.neon
34

45
parameters:
56
level: 10

‎rector.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Pest\Rector\Set\PestSetList;
67

78
return RectorConfig::configure()
89
->withPaths([
@@ -15,6 +16,9 @@
1516
removeUnusedImports: true,
1617
)
1718
->withPhpSets()
19+
->withSets([
20+
PestSetList::CODING_STYLE,
21+
])
1822
->withPreparedSets(
1923
deadCode: true,
2024
codeQuality: true,

‎src/Concerns/InputSanitization.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private function removeComments(string $input): string
166166
$this->log('Removing multi-line comment');
167167
$i += 2;
168168

169-
while ($i + 1 < $length && ! ($input[$i] === '*' && $input[$i + 1] === '/')) {
169+
while ($i + 1 < $length && ($input[$i] !== '*' || $input[$i + 1] !== '/')) {
170170
$i++;
171171
}
172172

‎tests/Pest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
namespace Cortex\JsonRepair\Tests;
66

7-
uses(TestCase::class)->in('Unit');
7+
pest()
8+
->extend(TestCase::class)
9+
->in('Unit');

‎tests/Unit/ApiUsageTest.php‎

Lines changed: 88 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,30 @@
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 {
@@ -54,8 +59,8 @@
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

@@ -64,17 +69,21 @@
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

@@ -83,39 +92,45 @@
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

@@ -142,33 +157,36 @@
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 {
@@ -178,9 +196,9 @@
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 {
@@ -190,9 +208,9 @@
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);
@@ -205,11 +223,12 @@
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

Comments
 (0)