Skip to content

Commit 1321adb

Browse files
Optimized the exceptions thrown by Json and Xml. (#2821)
* 统一InvalidArgumentException错误抛出及捕获 * Added test cases. Co-authored-by: 李铭昕 <[email protected]>
1 parent 4cedd1a commit 1321adb

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Server/Request/XmlParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Hyperf\HttpMessage\Exception\BadRequestHttpException;
1515
use Hyperf\HttpMessage\Server\RequestParserInterface;
1616
use Hyperf\Utils\Codec\Xml;
17-
use Hyperf\Utils\Exception\InvalidArgumentException;
17+
use InvalidArgumentException;
1818

1919
class XmlParser implements RequestParserInterface
2020
{

tests/RequestParserTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace HyperfTest\HttpMessage;
13+
14+
use Hyperf\HttpMessage\Exception\BadRequestHttpException;
15+
use Hyperf\HttpMessage\Server\Request\JsonParser;
16+
use Hyperf\HttpMessage\Server\Request\XmlParser;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @internal
21+
* @coversNothing
22+
*/
23+
class RequestParserTest extends TestCase
24+
{
25+
public function testJsonParserFailed()
26+
{
27+
$this->expectException(BadRequestHttpException::class);
28+
$parser = new JsonParser();
29+
$parser->parse('{"hy"', '');
30+
}
31+
32+
public function testXmlParserFailed()
33+
{
34+
$this->expectException(BadRequestHttpException::class);
35+
$parser = new XmlParser();
36+
$parser->parse('{"hy"', '');
37+
}
38+
}

0 commit comments

Comments
 (0)