From f1fabb0ffd9aafcec4ef1565bcbc5f40c48212bd Mon Sep 17 00:00:00 2001 From: brian978 Date: Sat, 13 Apr 2013 00:02:10 +0300 Subject: [PATCH 1/3] Added unit tests for the ClassMethods::hydrator() method to test the change from method_exists() to is_callable() --- test/HydratorTest.php | 22 ++++++++++++ .../ClassMethodsMagicMethodSetter.php | 28 +++++++++++++++ .../TestAsset/ClassMethodsProtectedSetter.php | 36 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 test/TestAsset/ClassMethodsMagicMethodSetter.php create mode 100644 test/TestAsset/ClassMethodsProtectedSetter.php diff --git a/test/HydratorTest.php b/test/HydratorTest.php index 69cd24784..2baca1e47 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -17,6 +17,8 @@ use Zend\Stdlib\Hydrator\Filter\FilterComposite; use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCase; use ZendTest\Stdlib\TestAsset\ClassMethodsFilterProviderInterface; +use ZendTest\Stdlib\TestAsset\ClassMethodsMagicMethodSetter; +use ZendTest\Stdlib\TestAsset\ClassMethodsProtectedSetter; use ZendTest\Stdlib\TestAsset\ClassMethodsUnderscore; use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCaseMissing; use ZendTest\Stdlib\TestAsset\ClassMethodsInvalidParameter; @@ -397,4 +399,24 @@ public function testObjectBasedFilters() $this->assertSame("bar", $data["foo"]); $this->assertSame("foo", $data["bar"]); } + + public function testHydratorClassMethodsWithProtectedSetter() + { + $hydrator = new ClassMethods(false); + $object = new ClassMethodsProtectedSetter(); + $hydrator->hydrate(array('foo' => 'bar', 'bar' => 'BAR'), $object); + $data = $hydrator->extract($object); + + $this->assertEquals($data['bar'], 'BAR'); + } + + public function testHydratorClassMethodsWithMagicMethodSetter() + { + $hydrator = new ClassMethods(false); + $object = new ClassMethodsMagicMethodSetter(); + $hydrator->hydrate(array('foo' => 'bar'), $object); + $data = $hydrator->extract($object); + + $this->assertEquals($data['foo'], 'bar'); + } } diff --git a/test/TestAsset/ClassMethodsMagicMethodSetter.php b/test/TestAsset/ClassMethodsMagicMethodSetter.php new file mode 100644 index 000000000..b1f936b38 --- /dev/null +++ b/test/TestAsset/ClassMethodsMagicMethodSetter.php @@ -0,0 +1,28 @@ + 3 && strtolower(substr($method, 3)) == 'foo') + { + $this->foo = $args[0]; + } + } + + public function getFoo() + { + return $this->foo; + } +} \ No newline at end of file diff --git a/test/TestAsset/ClassMethodsProtectedSetter.php b/test/TestAsset/ClassMethodsProtectedSetter.php new file mode 100644 index 000000000..97bcfa85e --- /dev/null +++ b/test/TestAsset/ClassMethodsProtectedSetter.php @@ -0,0 +1,36 @@ +foo = $foo; + } + + public function setBar($bar) + { + $this->bar = $bar; + } + + public function getFoo() + { + return $this->foo; + } + + public function getBar() + { + return $this->bar; + } +} \ No newline at end of file From fd4de0787707198da4a4bcc5c9d10a4e759b3d1e Mon Sep 17 00:00:00 2001 From: brian978 Date: Sat, 13 Apr 2013 00:07:01 +0300 Subject: [PATCH 2/3] Removed method from the ClassMethodsProtectedSetter TestAsset because it's not required in the tests --- test/TestAsset/ClassMethodsProtectedSetter.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/TestAsset/ClassMethodsProtectedSetter.php b/test/TestAsset/ClassMethodsProtectedSetter.php index 97bcfa85e..09176369f 100644 --- a/test/TestAsset/ClassMethodsProtectedSetter.php +++ b/test/TestAsset/ClassMethodsProtectedSetter.php @@ -24,11 +24,6 @@ public function setBar($bar) $this->bar = $bar; } - public function getFoo() - { - return $this->foo; - } - public function getBar() { return $this->bar; From efeef19e7ed20bbc33a4bef4c8cc078dbf010491 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 15 Apr 2013 06:44:23 -0500 Subject: [PATCH 3/3] [zendframework/zf2#4191] CS fixes - per php-cs-fixer --- test/TestAsset/ClassMethodsMagicMethodSetter.php | 5 ++--- test/TestAsset/ClassMethodsProtectedSetter.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/TestAsset/ClassMethodsMagicMethodSetter.php b/test/TestAsset/ClassMethodsMagicMethodSetter.php index b1f936b38..8cf00a150 100644 --- a/test/TestAsset/ClassMethodsMagicMethodSetter.php +++ b/test/TestAsset/ClassMethodsMagicMethodSetter.php @@ -15,8 +15,7 @@ class ClassMethodsMagicMethodSetter public function __call($method, $args) { - if(strlen($method) > 3 && strtolower(substr($method, 3)) == 'foo') - { + if(strlen($method) > 3 && strtolower(substr($method, 3)) == 'foo') { $this->foo = $args[0]; } } @@ -25,4 +24,4 @@ public function getFoo() { return $this->foo; } -} \ No newline at end of file +} diff --git a/test/TestAsset/ClassMethodsProtectedSetter.php b/test/TestAsset/ClassMethodsProtectedSetter.php index 09176369f..9f9085257 100644 --- a/test/TestAsset/ClassMethodsProtectedSetter.php +++ b/test/TestAsset/ClassMethodsProtectedSetter.php @@ -28,4 +28,4 @@ public function getBar() { return $this->bar; } -} \ No newline at end of file +}