From f585310079b066826f41bc81c7253350b661671c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 26 Sep 2012 19:14:36 +0200 Subject: [PATCH 1/3] Simplfy code --- src/Hydrator/ClassMethods.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Hydrator/ClassMethods.php b/src/Hydrator/ClassMethods.php index af5e43a57..f6280076b 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -63,12 +63,13 @@ public function extract($object) if (!preg_match('/^(get|has|is)[A-Z]\w*/', $method)) { continue; } + + $attribute = $method; if (preg_match('/^get/', $method)) { $attribute = substr($method, 3); $attribute = lcfirst($attribute); - } else { - $attribute = $method; } + if ($this->underscoreSeparatedKeys) { $attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute); } From 45d3f59d6ffcf89fae2bfd205fbe62ec2631efa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 26 Sep 2012 22:36:42 +0200 Subject: [PATCH 2/3] Toto --- src/Hydrator/ClassMethods.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hydrator/ClassMethods.php b/src/Hydrator/ClassMethods.php index f6280076b..ad565f88d 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -63,7 +63,7 @@ public function extract($object) if (!preg_match('/^(get|has|is)[A-Z]\w*/', $method)) { continue; } - + $attribute = $method; if (preg_match('/^get/', $method)) { $attribute = substr($method, 3); From 1063833c6d0be04e1b6b0cbeb368355854770fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Thu, 27 Sep 2012 11:03:15 +0200 Subject: [PATCH 3/3] Updated tests --- test/HydratorTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/HydratorTest.php b/test/HydratorTest.php index 1e4432e54..b44fca5f0 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -188,4 +188,19 @@ public function testHydratorClassMethodsDefaultBehaviorIsConvertUnderscoreToCame $this->assertEquals($test->getFooBar(), 'foo'); $this->assertEquals($test->getFooBarBaz(), 'bar'); } + + public function testHydratorClassMethodsCamelCaseWithSetterMissing() + { + $hydrator = new ClassMethods(false); + + $datas = $hydrator->extract($this->classMethodsCamelCaseMissing); + $this->assertTrue(isset($datas['fooBar'])); + $this->assertEquals($datas['fooBar'], '1'); + $this->assertTrue(isset($datas['fooBarBaz'])); + $this->assertFalse(isset($datas['foo_bar'])); + $test = $hydrator->hydrate(array('fooBar' => 'foo', 'fooBarBaz' => 1), $this->classMethodsCamelCaseMissing); + $this->assertSame($this->classMethodsCamelCaseMissing, $test); + $this->assertEquals($test->getFooBar(), 'foo'); + $this->assertEquals($test->getFooBarBaz(), '2'); + } }