From ba47d85ec578e7635eb8db76d58d2467a5b52a4e Mon Sep 17 00:00:00 2001 From: RomanKis Date: Wed, 15 Nov 2017 16:11:00 +0200 Subject: [PATCH 1/2] 9764: exception message is wrong and misleading in findAccessorMethodName() of Magento\Framework\Reflection\NameFinder --- .../Framework/Reflection/NameFinder.php | 3 ++- .../Reflection/Test/Unit/NameFinderTest.php | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Reflection/NameFinder.php b/lib/internal/Magento/Framework/Reflection/NameFinder.php index 97f4b2f81c128..5cd4ab744bb1b 100644 --- a/lib/internal/Magento/Framework/Reflection/NameFinder.php +++ b/lib/internal/Magento/Framework/Reflection/NameFinder.php @@ -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() ) ); diff --git a/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php b/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php index 9ddc6d6aa0c9a..ccf81305df6eb 100644 --- a/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php +++ b/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php @@ -37,7 +37,9 @@ 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() { @@ -47,11 +49,31 @@ public function testGetSetterMethodNameInvalidAttribute() /** * @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"); $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' + ); + } } From 0a76034167a2f92e1d066014f899e899d2e42768 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Thu, 16 Nov 2017 11:14:21 +0200 Subject: [PATCH 2/2] 9764: exception message is wrong and misleading in findAccessorMethodName() of Magento\Framework\Reflection\NameFinder --- .../Framework/Reflection/Test/Unit/NameFinderTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php b/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php index ccf81305df6eb..a467c4b7b5aad 100644 --- a/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php +++ b/lib/internal/Magento/Framework/Reflection/Test/Unit/NameFinderTest.php @@ -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); @@ -43,7 +43,7 @@ public function testGetSetterMethodName() */ 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'); } @@ -55,7 +55,7 @@ public function testGetSetterMethodNameInvalidAttribute() */ 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'); }