diff --git a/src/Hydrator/ClassMethods.php b/src/Hydrator/ClassMethods.php index f53eb885a..73781adaa 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -102,19 +102,13 @@ public function extract($object) if (!preg_match('/^(get|has|is)[A-Z]\w*/', $method)) { continue; } + + $attribute = $method; if (preg_match('/^get/', $method)) { - // setter verification - $setter = preg_replace('/^get/', 'set', $method); $attribute = substr($method, 3); $attribute = lcfirst($attribute); - } else { - // setter verification - $setter = 'set' . ucfirst($method); - $attribute = $method; - } - if (!in_array($setter, $methods)) { - continue; } + if ($this->underscoreSeparatedKeys) { $attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute); } diff --git a/test/HydratorTest.php b/test/HydratorTest.php index 70f352c60..8a30585e3 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -125,20 +125,6 @@ public function testHydratorClassMethodsCamelCase() $this->assertEquals($test->hasBar(), false); } - public function testHydratorClassMethodsCamelCaseWithSetterMissing() - { - $hydrator = new ClassMethods(false); - $datas = $hydrator->extract($this->classMethodsCamelCaseMissing); - $this->assertTrue(isset($datas['fooBar'])); - $this->assertEquals($datas['fooBar'], '1'); - $this->assertFalse(isset($datas['fooBarBaz'])); - $this->assertFalse(isset($datas['foo_bar'])); - $test = $hydrator->hydrate(array('fooBar' => 'foo'), $this->classMethodsCamelCaseMissing); - $this->assertSame($this->classMethodsCamelCaseMissing, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), '2'); - } - public function testHydratorClassMethodsUnderscore() { $hydrator = new ClassMethods(true); @@ -247,4 +233,19 @@ public function testUseWildStrategyAndOther() $this->assertEquals($datas['foo_bar'], '1'); $this->assertEquals($datas['foo_bar_baz'], 's:1:"2";'); } + + 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'); + } }