Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2426'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Oct 1, 2012
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
12 changes: 3 additions & 9 deletions src/Hydrator/ClassMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,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);
}
Expand Down
29 changes: 15 additions & 14 deletions test/HydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,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);
Expand Down Expand Up @@ -202,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');
}
}

0 comments on commit a08bcca

Please sign in to comment.