Skip to content

Commit

Permalink
Merge forwardport of #12303 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/12303.patch (created by @RomaKis) based on commit(s):
  1. ba47d85
  2. 0a76034

Fixed GitHub Issues in 2.3-develop branch:
  - #9764: exception message is wrong and misleading in findAccessorMethodName() of Magento\Framework\Reflection\NameFinder (reported by @dbsdsun)
  • Loading branch information
magento-engcom-team authored Jan 29, 2018
2 parents f9976b9 + ecfe901 commit 4c77e4f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/Reflection/NameFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public function findAccessorMethodName(
} else {
throw new \LogicException(
sprintf(
'Property "%s" does not have corresponding setter in class "%s".',
'Property "%s" does not have accessor method "%s" in class "%s".',
$camelCaseProperty,
$accessorName,
$class->getName()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp()

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

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

/**
* @expectedException \Exception
* @expectedExceptionMessageRegExp /Property "InvalidAttribute" does not have corresponding setter in class (.*?)/
* @codingStandardsIgnoreStart
* @expectedExceptionMessage Property "InvalidAttribute" does not have accessor method "setInvalidAttribute" in class "Magento\Framework\Reflection\Test\Unit\DataObject"
* @codingStandardsIgnoreEnd
*/
public function testGetSetterMethodNameInvalidAttribute()
{
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
$class = new ClassReflection(\Magento\Framework\Reflection\Test\Unit\DataObject::class);
$this->nameFinder->getSetterMethodName($class, 'InvalidAttribute');
}

/**
* @expectedException \Exception
* @expectedExceptionMessageRegExp /Property "ActivE" does not have corresponding setter in class (.*?)/
* @codingStandardsIgnoreStart
* @expectedExceptionMessage Property "ActivE" does not have accessor method "setActivE" in class "Magento\Framework\Reflection\Test\Unit\DataObject"
* @codingStandardsIgnoreEnd
*/
public function testGetSetterMethodNameWrongCamelCasedAttribute()
{
$class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
$class = new ClassReflection(\Magento\Framework\Reflection\Test\Unit\DataObject::class);
$this->nameFinder->getSetterMethodName($class, 'ActivE');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Property "Property" does not have accessor method "getProperty" in class "className".
*/
public function testFindAccessorMethodName()
{
$reflectionClass = $this->createMock(\Zend\Code\Reflection\ClassReflection::class);
$reflectionClass->expects($this->atLeastOnce())->method('hasMethod')->willReturn(false);
$reflectionClass->expects($this->atLeastOnce())->method('getName')->willReturn('className');

$this->nameFinder->findAccessorMethodName(
$reflectionClass,
'Property',
'getProperty',
'isProperty'
);
}
}

0 comments on commit 4c77e4f

Please sign in to comment.