Skip to content

Commit 86e25da

Browse files
author
Eugene Tulika
committed
MAGETWO-38070: Incorrect WSDL generation
- fixed CR comments - added tests
1 parent a0f3610 commit 86e25da

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

app/code/Magento/Webapi/Test/Unit/Model/Soap/Config/ClassReflectorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public function testReflectClassMethods()
4949

5050
public function testExtractMethodData()
5151
{
52-
$classReflection = new \Zend\Server\Reflection\ReflectionClass(
53-
new \ReflectionClass('\\Magento\\Webapi\\Test\\Unit\\Model\\Config\\TestServiceForClassReflector')
52+
$classReflection = new \Zend\Code\Reflection\ClassReflection(
53+
'\\Magento\\Webapi\\Test\\Unit\\Model\\Config\\TestServiceForClassReflector'
5454
);
55-
/** @var $methodReflection ReflectionMethod */
55+
/** @var $methodReflection \Zend\Code\Reflection\MethodReflection */
5656
$methodReflection = $classReflection->getMethods()[0];
5757
$methodData = $this->_classReflector->extractMethodData($methodReflection);
5858
$expectedResponse = $this->_getSampleReflectionData();

lib/internal/Magento/Framework/Reflection/Test/Unit/DataObject.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class DataObject
2020
*/
2121
protected $isActive;
2222

23+
/**
24+
* @var string
25+
*/
26+
private $name;
27+
2328
/**
2429
* @return string
2530
*/
@@ -55,4 +60,14 @@ public function setIsActive($isActive)
5560
$this->isActive = $isActive;
5661
return $this;
5762
}
63+
64+
/**
65+
* @param null|string $name Name of the attribute
66+
* @return $this
67+
*/
68+
public function setName($name = null)
69+
{
70+
$this->name = $name;
71+
return $this;
72+
}
5873
}

lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,24 @@ public function testFindSetterMethodNameWrongCamelCasedAttribute()
213213
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
214214
$this->_typeProcessor->findSetterMethodName($class, 'ActivE');
215215
}
216+
217+
/**
218+
* @expectedException \LogicException
219+
* @expectedExceptionMessageRegExp /@param annotation is incorrect for the parameter "name" \w+/
220+
*/
221+
public function testGetParamType()
222+
{
223+
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
224+
$methodReflection = $class->getMethod('setName');
225+
$paramsReflection = $methodReflection->getParameters();
226+
$this->_typeProcessor->getParamType($paramsReflection[0]);
227+
}
228+
229+
public function testGetParameterDescription()
230+
{
231+
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
232+
$methodReflection = $class->getMethod('setName');
233+
$paramsReflection = $methodReflection->getParameters();
234+
$this->assertEquals('Name of the attribute', $this->_typeProcessor->getParamDescription($paramsReflection[0]));
235+
}
216236
}

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,18 @@ public function processSimpleAndAnyType($value, $type)
473473
*
474474
* @param ParameterReflection $param
475475
* @return string
476-
* @throws \Exception
476+
* @throws \LogicException
477477
*/
478478
public function getParamType(ParameterReflection $param)
479479
{
480480
$type = $param->getType();
481481
if ($param->getType() == 'null') {
482-
throw new \Exception(sprintf(
483-
'Type declaration is incorrect for the parameter "%s" in annotation for a method in the class "%s".'
482+
throw new \LogicException(sprintf(
483+
'@param annotation is incorrect for the parameter "%s" in the method "%s:%s".'
484484
. ' First declared type should not be null. E.g. string|null',
485485
$param->getName(),
486-
$param->getDeclaringClass()->getName()
486+
$param->getDeclaringClass()->getName(),
487+
$param->getDeclaringFunction()->name
487488
));
488489
}
489490
if ($type == 'array') {
@@ -503,15 +504,19 @@ public function getParamType(ParameterReflection $param)
503504
* Get parameter description
504505
*
505506
* @param ParameterReflection $param
506-
* @return mixed
507+
* @return string|null
507508
*/
508509
public function getParamDescription(ParameterReflection $param)
509510
{
510511
$docBlock = $param->getDeclaringFunction()->getDocBlock();
511-
$pattern = "/\@param\s+([\w\\\_\[\]]+)\s+(\\\${$param->getName()})(.*)\n/";
512+
$docBlockLines = explode("\n", $docBlock->getContents());
513+
$pattern = "/\@param\s+([\w\\\_\[\]\|]+)\s+(\\\${$param->getName()})\s(.*)/";
512514
$matches = [];
513-
if (preg_match($pattern, $docBlock->getContents(), $matches)) {
514-
return $matches[3];
515+
516+
foreach ($docBlockLines as $line) {
517+
if (preg_match($pattern, $line, $matches)) {
518+
return $matches[3];
519+
}
515520
}
516521
}
517522

0 commit comments

Comments
 (0)