Skip to content

Commit 94fe76c

Browse files
author
Evgeny Kalashnikov
committed
Code generate: add test variadic parameter
1 parent 405482b commit 94fe76c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/internal/Magento/Framework/Code/Test/Unit/Generator/ClassGeneratorTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class ClassGeneratorTest extends \PHPUnit\Framework\TestCase
2020

2121
const FLAG_REFERENCE = 'passedByReference';
2222

23+
const FLAG_VARIADIC = 'variadic';
24+
2325
/**#@-*/
2426

2527
/**
@@ -38,6 +40,7 @@ class ClassGeneratorTest extends \PHPUnit\Framework\TestCase
3840
self::FLAG_FINAL => 'isFinal',
3941
self::FLAG_ABSTRACT => 'isAbstract',
4042
self::FLAG_REFERENCE => 'getPassedByReference',
43+
self::FLAG_VARIADIC => 'getVariadic',
4144
];
4245

4346
/**
@@ -65,7 +68,7 @@ class ClassGeneratorTest extends \PHPUnit\Framework\TestCase
6568
'final' => true,
6669
'static' => true,
6770
'parameters' => [
68-
['name' => 'data', 'type' => 'array', 'defaultValue' => [], 'passedByReference' => true],
71+
['name' => 'data', 'type' => 'array', 'defaultValue' => [], 'passedByReference' => true, 'variadic' => false],
6972
],
7073
'body' => 'return 1;',
7174
'docblock' => ['shortDescription' => 'test short description'],
@@ -205,6 +208,9 @@ public function testAddMethods()
205208
$actualDefaultValue = $actualParameter->getDefaultValue();
206209
$this->assertEquals($parameterData['defaultValue'], $actualDefaultValue->getValue());
207210
}
211+
212+
// assert variadic flag
213+
$this->_assertFlag(self::FLAG_VARIADIC, $parameterData, $actualParameter);
208214
}
209215
}
210216

lib/internal/Magento/Framework/Interception/Test/Unit/Code/Generator/_files/Interceptor.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,17 @@ class Interceptor extends \Magento\Framework\Interception\Code\Generator\Sample
5050
return $this->___callPlugins('getReference', func_get_args(), $pluginInfo);
5151
}
5252
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function variadic(... $values)
58+
{
59+
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'variadic');
60+
if (!$pluginInfo) {
61+
return parent::variadic(... $values);
62+
} else {
63+
return $this->___callPlugins('variadic', func_get_args(), $pluginInfo);
64+
}
65+
}
5366
}

lib/internal/Magento/Framework/Interception/Test/Unit/Code/Generator/_files/Sample.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ public function setValue($value)
2222
public function & getReference()
2323
{
2424
}
25+
26+
public function variadic(... $values)
27+
{
28+
}
2529
}

0 commit comments

Comments
 (0)