Skip to content

Commit 1b49390

Browse files
committed
Add the missing JSON_THROW_ON_ERROR flags
1 parent 0bfbb80 commit 1b49390

File tree

8 files changed

+65
-44
lines changed

8 files changed

+65
-44
lines changed

src/Routing/ResponseContext/JsonLd/JsonLdManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function collectFinalScriptFromGraphs(): string
6767

6868
ArrayUtil::recursiveKeySort($data);
6969

70-
return '<script type="application/ld+json">'."\n".json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)."\n".'</script>';
70+
return '<script type="application/ld+json">'."\n".json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)."\n".'</script>';
7171
}
7272

7373
/**

tests/Controller/BackendPreviewSwitchControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function testReturnsEmptyMemberList(): void
242242

243243
$this->assertInstanceOf(JsonResponse::class, $response);
244244
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
245-
$this->assertSame(json_encode([]), $response->getContent());
245+
$this->assertSame(json_encode([], JSON_THROW_ON_ERROR), $response->getContent());
246246
}
247247

248248
public function testExitsAsUnauthenticatedUser(): void

tests/Monolog/ContaoContextTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ public function testSupportsReadingAndWritingValues(): void
3838
$context->setUri('https://www.contao.org');
3939
$context->setPageId(42);
4040

41-
$json = json_encode([
42-
'func' => 'foo',
43-
'action' => 'action',
44-
'username' => 'username',
45-
'browser' => 'Mozilla',
46-
'uri' => 'https://www.contao.org',
47-
'pageId' => 42,
48-
]);
41+
$json = json_encode(
42+
[
43+
'func' => 'foo',
44+
'action' => 'action',
45+
'username' => 'username',
46+
'browser' => 'Mozilla',
47+
'uri' => 'https://www.contao.org',
48+
'pageId' => 42,
49+
],
50+
JSON_THROW_ON_ERROR
51+
);
4952

5053
$this->assertSame($json, (string) $context);
5154
}

tests/Picker/ArticlePickerProviderTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ protected function tearDown(): void
4343

4444
public function testCreatesTheMenuItem(): void
4545
{
46-
$config = json_encode([
47-
'context' => 'link',
48-
'extras' => [],
49-
'current' => 'articlePicker',
50-
'value' => '',
51-
]);
46+
$config = json_encode(
47+
[
48+
'context' => 'link',
49+
'extras' => [],
50+
'current' => 'articlePicker',
51+
'value' => '',
52+
],
53+
JSON_THROW_ON_ERROR
54+
);
5255

5356
if (\function_exists('gzencode') && false !== ($encoded = @gzencode($config))) {
5457
$config = $encoded;

tests/Picker/FilePickerProviderTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ class FilePickerProviderTest extends TestCase
2828
{
2929
public function testCreatesTheMenuItem(): void
3030
{
31-
$config = json_encode([
32-
'context' => 'link',
33-
'extras' => [],
34-
'current' => 'filePicker',
35-
'value' => '',
36-
]);
31+
$config = json_encode(
32+
[
33+
'context' => 'link',
34+
'extras' => [],
35+
'current' => 'filePicker',
36+
'value' => '',
37+
],
38+
JSON_THROW_ON_ERROR
39+
);
3740

3841
if (\function_exists('gzencode') && false !== ($encoded = @gzencode($config))) {
3942
$config = $encoded;

tests/Picker/PagePickerProviderTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ class PagePickerProviderTest extends ContaoTestCase
2626
{
2727
public function testCreatesTheMenuItem(): void
2828
{
29-
$config = json_encode([
30-
'context' => 'link',
31-
'extras' => [],
32-
'current' => 'pagePicker',
33-
'value' => '',
34-
]);
29+
$config = json_encode(
30+
[
31+
'context' => 'link',
32+
'extras' => [],
33+
'current' => 'pagePicker',
34+
'value' => '',
35+
],
36+
JSON_THROW_ON_ERROR
37+
);
3538

3639
if (\function_exists('gzencode') && false !== ($encoded = @gzencode($config))) {
3740
$config = $encoded;

tests/Picker/PickerConfigTest.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ public function testSerializesItselfToAnArray(): void
7979

8080
public function testCreatesAnEncodedJsonString(): void
8181
{
82-
$data = json_encode([
83-
'context' => 'link',
84-
'extras' => ['fieldType' => 'radio'],
85-
'current' => 'alias',
86-
'value' => 'foo',
87-
]);
82+
$data = json_encode(
83+
[
84+
'context' => 'link',
85+
'extras' => ['fieldType' => 'radio'],
86+
'current' => 'alias',
87+
'value' => 'foo',
88+
],
89+
JSON_THROW_ON_ERROR
90+
);
8891

8992
if (\function_exists('gzencode') && false !== ($encoded = @gzencode($data))) {
9093
$data = $encoded;
@@ -95,12 +98,15 @@ public function testCreatesAnEncodedJsonString(): void
9598

9699
public function testDecodesAnEncodedJsonString(): void
97100
{
98-
$data = json_encode([
99-
'context' => 'link',
100-
'extras' => ['fieldType' => 'radio'],
101-
'current' => 'alias',
102-
'value' => 'foo',
103-
]);
101+
$data = json_encode(
102+
[
103+
'context' => 'link',
104+
'extras' => ['fieldType' => 'radio'],
105+
'current' => 'alias',
106+
'value' => 'foo',
107+
],
108+
JSON_THROW_ON_ERROR
109+
);
104110

105111
if (\function_exists('gzencode') && false !== ($encoded = @gzencode($data))) {
106112
$data = $encoded;

tests/Security/TwoFactor/BackupCodeManagerTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ public function testHandlesContaoUsers(): void
8282

8383
public function testInvalidatesBackupCode(): void
8484
{
85-
$backupCodes = json_encode([
86-
'$2y$10$vY0fVrqfUmzzHSQpT6ZMPOGwrYLq.9s/Y1M9cV9/0K0SlGH/kMotC', // 4ead45-4ea70a
87-
'$2y$10$Ie2VHgQLiNTfAI1kDV19U.i9dsvIE4tt3h75rpVHnoWqJFS0Lq1Yy', // 0082ec-b95f03
88-
]);
85+
$backupCodes = json_encode(
86+
[
87+
'$2y$10$vY0fVrqfUmzzHSQpT6ZMPOGwrYLq.9s/Y1M9cV9/0K0SlGH/kMotC', // 4ead45-4ea70a
88+
'$2y$10$Ie2VHgQLiNTfAI1kDV19U.i9dsvIE4tt3h75rpVHnoWqJFS0Lq1Yy', // 0082ec-b95f03
89+
],
90+
JSON_THROW_ON_ERROR
91+
);
8992

9093
$user = $this->mockClassWithProperties(BackendUser::class);
9194
$user->backupCodes = $backupCodes;

0 commit comments

Comments
 (0)