Skip to content

Commit f2f94cf

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1733 from magento-engcom/2.2-develop-prs
Public Pull Requests #12303 9764: exception message is wrong and misleading in findAccessorMethodName() of Magento\Framework\Reflection\NameFinder by @RomaKis Fixed Public Issues #9764 exception message is wrong and misleading in findAccessorMethodName() of Magento\Framework\Reflection\NameFinder
2 parents 1d5208b + a6f226f commit f2f94cf

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public function findAccessorMethodName(
9999
} else {
100100
throw new \LogicException(
101101
sprintf(
102-
'Property "%s" does not have corresponding setter in class "%s".',
102+
'Property "%s" does not have accessor method "%s" in class "%s".',
103103
$camelCaseProperty,
104+
$accessorName,
104105
$class->getName()
105106
)
106107
);

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function setUp()
2727

2828
public function testGetSetterMethodName()
2929
{
30-
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
30+
$class = new ClassReflection(\Magento\Framework\Reflection\Test\Unit\DataObject::class);
3131
$setterName = $this->nameFinder->getSetterMethodName($class, 'AttrName');
3232
$this->assertEquals("setAttrName", $setterName);
3333

@@ -37,21 +37,43 @@ public function testGetSetterMethodName()
3737

3838
/**
3939
* @expectedException \Exception
40-
* @expectedExceptionMessageRegExp /Property "InvalidAttribute" does not have corresponding setter in class (.*?)/
40+
* @codingStandardsIgnoreStart
41+
* @expectedExceptionMessage Property "InvalidAttribute" does not have accessor method "setInvalidAttribute" in class "Magento\Framework\Reflection\Test\Unit\DataObject"
42+
* @codingStandardsIgnoreEnd
4143
*/
4244
public function testGetSetterMethodNameInvalidAttribute()
4345
{
44-
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
46+
$class = new ClassReflection(\Magento\Framework\Reflection\Test\Unit\DataObject::class);
4547
$this->nameFinder->getSetterMethodName($class, 'InvalidAttribute');
4648
}
4749

4850
/**
4951
* @expectedException \Exception
50-
* @expectedExceptionMessageRegExp /Property "ActivE" does not have corresponding setter in class (.*?)/
52+
* @codingStandardsIgnoreStart
53+
* @expectedExceptionMessage Property "ActivE" does not have accessor method "setActivE" in class "Magento\Framework\Reflection\Test\Unit\DataObject"
54+
* @codingStandardsIgnoreEnd
5155
*/
5256
public function testGetSetterMethodNameWrongCamelCasedAttribute()
5357
{
54-
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
58+
$class = new ClassReflection(\Magento\Framework\Reflection\Test\Unit\DataObject::class);
5559
$this->nameFinder->getSetterMethodName($class, 'ActivE');
5660
}
61+
62+
/**
63+
* @expectedException \LogicException
64+
* @expectedExceptionMessage Property "Property" does not have accessor method "getProperty" in class "className".
65+
*/
66+
public function testFindAccessorMethodName()
67+
{
68+
$reflectionClass = $this->createMock(\Zend\Code\Reflection\ClassReflection::class);
69+
$reflectionClass->expects($this->atLeastOnce())->method('hasMethod')->willReturn(false);
70+
$reflectionClass->expects($this->atLeastOnce())->method('getName')->willReturn('className');
71+
72+
$this->nameFinder->findAccessorMethodName(
73+
$reflectionClass,
74+
'Property',
75+
'getProperty',
76+
'isProperty'
77+
);
78+
}
5779
}

0 commit comments

Comments
 (0)