Skip to content

Commit

Permalink
catch InvalidArgumentException, throw correct message, unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtsiomBruneuski authored and gelanivishal committed Oct 12, 2018
1 parent 3109909 commit 9afdfee
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/internal/Magento/Framework/Communication/Config/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
class Validator
{
const INVALID_ANNOTATIONS = 123;
/**
* @var TypeProcessor
*/
Expand Down Expand Up @@ -47,7 +48,11 @@ public function validateResponseSchemaType($responseSchema, $topicName)
try {
$this->validateType($responseSchema);
} catch (\InvalidArgumentException $e) {
throw $e;
throw new \LogicException(
'Response schema definition has wrong annotations',
self::INVALID_ANNOTATIONS,
$e
);
} catch (\Exception $e) {
throw new \LogicException(
sprintf(
Expand All @@ -70,7 +75,11 @@ public function validateRequestSchemaType($requestSchema, $topicName)
try {
$this->validateType($requestSchema);
} catch (\InvalidArgumentException $e) {
throw $e;
throw new \LogicException(
'Response schema definition has wrong annotations',
self::INVALID_ANNOTATIONS,
$e
);
} catch (\Exception $e) {
throw new \LogicException(
sprintf(
Expand All @@ -94,8 +103,6 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler
{
try {
$this->methodsMap->getMethodParams($serviceName, $methodName);
} catch (\InvalidArgumentException $e) {
throw $e;
} catch (\Exception $e) {
throw new \LogicException(
sprintf(
Expand All @@ -115,6 +122,7 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler
* @param string $typeName
* @return $this
* @throws \Exception In case when type is invalid
* @throws \InvalidArgumentException
*/
protected function validateType($typeName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* m2git
*/

namespace Magento\Framework\Test\Unit\Communication\Config;


use Magento\Framework\Communication\Config\Validator;
use Magento\Framework\Reflection\MethodsMap;
use Magento\Framework\Reflection\TypeProcessor;

class ValidatorTest extends \PHPUnit\Framework\TestCase
{
protected $typeProcessor;
protected $methodsMap;

public function setUp()
{
$this->methodsMap = $this->createMock(MethodsMap::class);

$this->methodsMap->expects(static::any())
->method('getMethodsMap')
->will($this->throwException(new \InvalidArgumentException()));


$this->typeProcessor = $this->createMock(TypeProcessor::class);
$this->typeProcessor->expects(static::any())
->method('isTypeSimple')
->willReturn(false);

$this->typeProcessor->expects(static::any())
->method('isTypeSimple')
->willReturn(false);
}

/**
* @expectedException \LogicException
* @expectedExceptionCode 123
*/
public function testValidateResponseSchemaType()
{
/** @var Validator $validator */
$validator = new Validator($this->typeProcessor, $this->methodsMap);
$validator->validateResponseSchemaType('123', '123');
}

/**
* @expectedException \LogicException
* @expectedExceptionCode 123
*/
public function testValidateRequestSchemaType()
{
/** @var Validator $validator */
$validator = new Validator($this->typeProcessor, $this->methodsMap);
$validator->validateRequestSchemaType('123', '123');
}
}

0 comments on commit 9afdfee

Please sign in to comment.