12 use Zend\Code\Reflection\ClassReflection;
19 private $typeProcessor;
34 $this->typeProcessor->setTypeData(
'typeA', [
'dataA']);
35 $this->typeProcessor->setTypeData(
'typeB', [
'dataB']);
37 [
'typeA' => [
'dataA'],
'typeB' => [
'dataB']],
38 $this->typeProcessor->getTypesData()
47 $this->typeProcessor->setTypeData(
'typeC', [
'dataC']);
48 $this->assertEquals([
'typeC' => [
'dataC']], $this->typeProcessor->getTypesData());
49 $typeData = [
'typeA' => [
'dataA'],
'typeB' => [
'dataB']];
50 $this->typeProcessor->setTypesData($typeData);
51 $this->assertEquals($typeData, $this->typeProcessor->getTypesData());
60 $this->typeProcessor->getTypeData(
'NonExistentType');
68 $this->typeProcessor->setTypeData(
'typeA', [
'dataA']);
69 $this->assertEquals([
'dataA'], $this->typeProcessor->getTypeData(
'typeA'));
77 $this->typeProcessor->setTypeData(
'typeA', [
'dataA1']);
78 $this->typeProcessor->setTypeData(
'typeA', [
'dataA2']);
79 $this->typeProcessor->setTypeData(
'typeA', [
'dataA3']);
80 $this->typeProcessor->setTypeData(
'typeA', [
null]);
82 [
'dataA1',
'dataA2',
'dataA3',
null],
83 $this->typeProcessor->getTypeData(
'typeA')
89 $this->assertEquals(
'blah', $this->typeProcessor->normalizeType(
'blah'));
90 $this->assertEquals(
'string', $this->typeProcessor->normalizeType(
'str'));
91 $this->assertEquals(
'int', $this->typeProcessor->normalizeType(
'integer'));
92 $this->assertEquals(
'boolean', $this->typeProcessor->normalizeType(
'bool'));
93 $this->assertEquals(
'anyType', $this->typeProcessor->normalizeType(
'mixed'));
98 $this->assertTrue($this->typeProcessor->isTypeSimple(
'string'));
99 $this->assertTrue($this->typeProcessor->isTypeSimple(
'string[]'));
100 $this->assertTrue($this->typeProcessor->isTypeSimple(
'int'));
101 $this->assertTrue($this->typeProcessor->isTypeSimple(
'float'));
102 $this->assertTrue($this->typeProcessor->isTypeSimple(
'double'));
103 $this->assertTrue($this->typeProcessor->isTypeSimple(
'boolean'));
104 $this->assertFalse($this->typeProcessor->isTypeSimple(
'blah'));
109 $this->assertTrue($this->typeProcessor->isTypeAny(
'mixed'));
110 $this->assertTrue($this->typeProcessor->isTypeAny(
'mixed[]'));
111 $this->assertFalse($this->typeProcessor->isTypeAny(
'int'));
112 $this->assertFalse($this->typeProcessor->isTypeAny(
'int[]'));
117 $this->assertFalse($this->typeProcessor->isArrayType(
'string'));
118 $this->assertTrue($this->typeProcessor->isArrayType(
'string[]'));
123 $this->assertTrue($this->typeProcessor->isValidTypeDeclaration(
'Traversable'));
124 $this->assertTrue($this->typeProcessor->isValidTypeDeclaration(
'stdObj'));
125 $this->assertTrue($this->typeProcessor->isValidTypeDeclaration(
'array'));
126 $this->assertTrue($this->typeProcessor->isValidTypeDeclaration(
'callable'));
127 $this->assertTrue($this->typeProcessor->isValidTypeDeclaration(
'self'));
128 $this->assertTrue($this->typeProcessor->isValidTypeDeclaration(
'self'));
129 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'string'));
130 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'string[]'));
131 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'int'));
132 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'float'));
133 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'double'));
134 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'boolean'));
135 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'[]'));
136 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'mixed[]'));
137 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'stdObj[]'));
138 $this->assertFalse($this->typeProcessor->isValidTypeDeclaration(
'Traversable[]'));
143 $this->assertEquals(
'string', $this->typeProcessor->getArrayItemType(
'str[]'));
144 $this->assertEquals(
'string', $this->typeProcessor->getArrayItemType(
'string[]'));
145 $this->assertEquals(
'integer', $this->typeProcessor->getArrayItemType(
'int[]'));
146 $this->assertEquals(
'boolean', $this->typeProcessor->getArrayItemType(
'bool[]'));
147 $this->assertEquals(
'any', $this->typeProcessor->getArrayItemType(
'mixed[]'));
153 'TestModule1V1EntityItem',
154 $this->typeProcessor->translateTypeName(\
Magento\TestModule1\Service\V1\Entity\Item::class)
157 'TestModule3V1EntityParameter[]',
158 $this->typeProcessor->translateTypeName(
'\Magento\TestModule3\Service\V1\Entity\Parameter[]')
168 $this->typeProcessor->translateTypeName(
'\Magento\TestModule3\V1\Parameter[]');
173 $this->assertEquals(
'ArrayOfComplexType', $this->typeProcessor->translateArrayTypeName(
'complexType'));
180 $this->assertSame(
'1', $this->typeProcessor->processSimpleAndAnyType(
$value,
$type));
187 $this->assertSame(1, $this->typeProcessor->processSimpleAndAnyType(
$value,
$type));
194 $this->assertSame(1, $this->typeProcessor->processSimpleAndAnyType(
$value,
$type));
201 $this->assertSame([
'1',
'2',
'3',
'4',
'5'], $this->typeProcessor->processSimpleAndAnyType(
$value,
$type));
206 $value = [
'1',
'2',
'3',
'4',
'5'];
208 $this->assertSame([1, 2, 3, 4, 5], $this->typeProcessor->processSimpleAndAnyType(
$value,
$type));
216 $this->expectException(
217 SerializationException::class,
218 'Invalid type for value: "' .
$value .
'". Expected Type: "' .
$type .
'"' 220 $this->typeProcessor->processSimpleAndAnyType(
$value,
$type);
229 "int type, string value" => [
'test',
'int'],
230 "float type, string value" => [
'test',
'float'],
242 $this->typeProcessor->processSimpleAndAnyType(
$value,
$type);
251 $class =
new ClassReflection(DataObject::class);
252 $methodReflection =
$class->getMethod(
'setName');
253 $paramsReflection = $methodReflection->getParameters();
254 $this->typeProcessor->getParamType($paramsReflection[0]);
266 $class =
new ClassReflection(DataObject::class);
267 $methodReflection =
$class->getMethod($methodName);
268 $params = $methodReflection->getParameters();
269 $this->assertEquals(
$type, $this->typeProcessor->getParamType(array_pop(
$params)));
280 [
'method name' =>
'addData',
'type' =>
'array[]'],
281 [
'method name' =>
'addObjectList',
'type' =>
'TSampleInterface[]']
294 $class =
new ClassReflection(DataObject::class);
295 $methodReflection =
$class->getMethod($methodName);
296 $paramsReflection = $methodReflection->getParameters();
297 foreach ($paramsReflection as $paramReflection) {
301 $this->typeProcessor->getParamDescription($paramReflection)
314 [
'method name' =>
'setName',
'descriptions' => [
'Name of the attribute']],
315 [
'method name' =>
'setData',
'descriptions' => [
'Key is used as index',
null]],
323 $this->typeProcessor->getOperationName(
"resName",
"methodName")
334 'isRequired' =>
true,
335 'description' =>
null,
336 'parameterCount' => 0
339 $classReflection =
new ClassReflection(TSample::class);
340 $methodReflection = $classReflection->getMethod(
'getPropertyName');
342 self::assertEquals($expected, $this->typeProcessor->getGetterReturnType($methodReflection));
353 $classReflection =
new ClassReflection(TSample::class);
354 $methodReflection = $classReflection->getMethod(
'getName');
355 $this->typeProcessor->getGetterReturnType($methodReflection);
testProcessSimpleTypeInvalidType()
testGetParameterDescription(string $methodName, array $descriptions)
methodParamsDataProvider()
testProcessSimpleTypeIntToString()
testIsValidTypeDeclaration()
testSetTypeDataArrayMerge()
testTranslateTypeNameInvalidArgumentException()
testProcessSimpleTypeStringArrayToIntArray()
testTranslateArrayTypeName()
$_option $_optionId $class
testProcessSimpleTypeIntArrayToStringArray()
static processSimpleTypeExceptionProvider()
testProcessSimpleTypeMixed()
testGetArrayParamType(string $methodName, string $type)
testGetReturnTypeWithoutReturnTag()
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
testProcessSimpleTypeStringToInt()
testProcessSimpleTypeException($value, $type)
testGetTypeDataInvalidArgumentException()
testGetParamTypeWithIncorrectAnnotation()
arrayParamTypeDataProvider()
testGetReturnTypeWithInheritDocBlock()