Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9764: exception message is wrong and misleading in findAccessorMethodName() of Magento\Framework\Reflection\NameFinder #12303

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
);
}
}