Skip to content

Commit 4f017f8

Browse files
catch InvalidArgumentException, throw correct message, unit test
1 parent 9a1b8fd commit 4f017f8

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

lib/internal/Magento/Framework/Communication/Config/Validator.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
class Validator
1515
{
16+
const INVALID_ANNOTATIONS = 123;
1617
/**
1718
* @var TypeProcessor
1819
*/
@@ -47,7 +48,11 @@ public function validateResponseSchemaType($responseSchema, $topicName)
4748
try {
4849
$this->validateType($responseSchema);
4950
} catch (\InvalidArgumentException $e) {
50-
throw $e;
51+
throw new \LogicException(
52+
'Response schema definition has wrong annotations',
53+
self::INVALID_ANNOTATIONS,
54+
$e
55+
);
5156
} catch (\Exception $e) {
5257
throw new \LogicException(
5358
sprintf(
@@ -70,7 +75,11 @@ public function validateRequestSchemaType($requestSchema, $topicName)
7075
try {
7176
$this->validateType($requestSchema);
7277
} catch (\InvalidArgumentException $e) {
73-
throw $e;
78+
throw new \LogicException(
79+
'Response schema definition has wrong annotations',
80+
self::INVALID_ANNOTATIONS,
81+
$e
82+
);
7483
} catch (\Exception $e) {
7584
throw new \LogicException(
7685
sprintf(
@@ -94,8 +103,6 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler
94103
{
95104
try {
96105
$this->methodsMap->getMethodParams($serviceName, $methodName);
97-
} catch (\InvalidArgumentException $e) {
98-
throw $e;
99106
} catch (\Exception $e) {
100107
throw new \LogicException(
101108
sprintf(
@@ -115,6 +122,7 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler
115122
* @param string $typeName
116123
* @return $this
117124
* @throws \Exception In case when type is invalid
125+
* @throws \InvalidArgumentException
118126
*/
119127
protected function validateType($typeName)
120128
{
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* m2git
4+
*/
5+
6+
namespace Magento\Framework\Test\Unit\Communication\Config;
7+
8+
9+
use Magento\Framework\Communication\Config\Validator;
10+
use Magento\Framework\Reflection\MethodsMap;
11+
use Magento\Framework\Reflection\TypeProcessor;
12+
13+
class ValidatorTest extends \PHPUnit\Framework\TestCase
14+
{
15+
protected $typeProcessor;
16+
protected $methodsMap;
17+
18+
public function setUp()
19+
{
20+
$this->methodsMap = $this->createMock(MethodsMap::class);
21+
22+
$this->methodsMap->expects(static::any())
23+
->method('getMethodsMap')
24+
->will($this->throwException(new \InvalidArgumentException()));
25+
26+
27+
$this->typeProcessor = $this->createMock(TypeProcessor::class);
28+
$this->typeProcessor->expects(static::any())
29+
->method('isTypeSimple')
30+
->willReturn(false);
31+
32+
$this->typeProcessor->expects(static::any())
33+
->method('isTypeSimple')
34+
->willReturn(false);
35+
}
36+
37+
/**
38+
* @expectedException \LogicException
39+
* @expectedExceptionCode 123
40+
*/
41+
public function testValidateResponseSchemaType()
42+
{
43+
/** @var Validator $validator */
44+
$validator = new Validator($this->typeProcessor, $this->methodsMap);
45+
$validator->validateResponseSchemaType('123', '123');
46+
}
47+
48+
/**
49+
* @expectedException \LogicException
50+
* @expectedExceptionCode 123
51+
*/
52+
public function testValidateRequestSchemaType()
53+
{
54+
/** @var Validator $validator */
55+
$validator = new Validator($this->typeProcessor, $this->methodsMap);
56+
$validator->validateRequestSchemaType('123', '123');
57+
}
58+
}

0 commit comments

Comments
 (0)