Skip to content

Commit 0a8ee90

Browse files
author
Oleksii Korshenko
authored
MAGETWO-69019: #8607: Interface constructor if present will break Magento compilation #9524
2 parents 847d23f + 89d43e8 commit 0a8ee90

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ public function getConstructorArguments(\ReflectionClass $class, $groupByPositio
2525
/**
2626
* Skip native PHP types, classes without constructor
2727
*/
28-
if (!$class->getFileName() || false == $class->hasMethod(
29-
'__construct'
30-
) || !$inherited && $class->getConstructor()->class != $class->getName()
28+
if ($class->isInterface() ||
29+
!$class->getFileName() ||
30+
false == $class->hasMethod('__construct') ||
31+
!$inherited &&
32+
$class->getConstructor()->class != $class->getName()
3133
) {
3234
return $output;
3335
}

lib/internal/Magento/Framework/Code/Test/Unit/Reader/ArgumentsReaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ public function testGetConstructorArgumentsClassWithoutOwnConstructorInheritedFa
8686
$this->assertEquals([], $actualResult);
8787
}
8888

89+
public function testGetConstructorArgumentsWhenInputTypeIsInterfaceWithParam()
90+
{
91+
$class = new \ReflectionClass('InterfaceTypeWithConstructorMethodAndParams');
92+
$actualResult = $this->_model->getConstructorArguments($class);
93+
$this->assertEquals([], $actualResult);
94+
}
95+
96+
public function testGetConstructorArgumentsWhenInputTypeIsInterfaceWithoutParam()
97+
{
98+
$class = new \ReflectionClass('InterfaceTypeWithConstructorMethodWithoutParams');
99+
$actualResult = $this->_model->getConstructorArguments($class);
100+
$this->assertEquals([], $actualResult);
101+
}
102+
89103
public function testGetConstructorArgumentsClassWithoutOwnConstructorInheritedTrue()
90104
{
91105
$expectedResult = [

lib/internal/Magento/Framework/Code/Test/Unit/Reader/_files/ClassesForArgumentsReader.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,21 @@ public function __construct(\stdClass $stdClassObject, \ClassExtendsDefaultPhpTy
223223
$this->argumentTwo = $secondClass;
224224
}
225225
}
226+
227+
interface InterfaceTypeWithConstructorMethodAndParams
228+
{
229+
/**
230+
* We do not expect that this is valid case. There is no need to declare interface with method __construct
231+
*
232+
* @param $paramOne
233+
* @param $paramTwo
234+
*/
235+
public function __construct($paramOne, $paramTwo);
236+
}
237+
interface InterfaceTypeWithConstructorMethodWithoutParams
238+
{
239+
/**
240+
* We do not expect that this is valid case. There is no need to declare interface with method __construct
241+
*/
242+
public function __construct();
243+
}

0 commit comments

Comments
 (0)