Skip to content

Commit bfcae8d

Browse files
committed
test: add test for getJSON() and JSON_THROW_ON_ERROR
1 parent a3a7134 commit bfcae8d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Test\CIUnitTestCase;
1919
use Config\App;
2020
use InvalidArgumentException;
21+
use JsonException;
2122
use TypeError;
2223

2324
/**
@@ -541,6 +542,19 @@ public function testGetJSONWithInvalidJSONString(): void
541542
$request->getJSON();
542543
}
543544

545+
public function testGetJSONWithJsonThrowOnErrorAndInvalidJSONString(): void
546+
{
547+
$this->expectException(JsonException::class);
548+
$this->expectExceptionMessage('Syntax error');
549+
550+
$config = new App();
551+
$config->baseURL = 'http://example.com/';
552+
$json = 'Invalid JSON string';
553+
$request = $this->createRequest($config, $json);
554+
555+
$request->getJSON(false, 512, JSON_THROW_ON_ERROR);
556+
}
557+
544558
public function testCanGrabGetRawInput(): void
545559
{
546560
$rawstring = 'username=admin001&role=administrator&usepass=0';

0 commit comments

Comments
 (0)