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

Commit

Permalink
Merge branch 'feature/3754' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 15, 2013
187 parents dc57268 + 714d1a8 + 84b0297 + cbc5f03 + 76361f8 + e7209df + 87630e0 + df43daf + f7d6cbb + 7e2b798 + 3ed1ead + 87505b6 + c229265 + eb61c8f + efcb00e + 0a0842f + b6d0c88 + 7edee62 + 60ea64c + a08bcca + b40ec3e + 63172ed + 448f428 + 92a516a + 5ecbc99 + a2df21b + 4de87f2 + 7c259ec + a22bdcb + 084ad9f + 9414e5a + 489be93 + cb39e7e + 54a28dc + c9c769e + dda791d + 70d382a + 8bbad0e + 9321185 + 7ab35a6 + b93694e + 3ea7087 + 0fe3d3a + bd5e189 + d1cba17 + 8d75392 + 3fb5b55 + 6cb0ccb + 30aa565 + 8409977 + 8074ba0 + 8f92486 + 94860d1 + 05d33c4 + 425826b + f0e91f0 + e31468f + 7d2af87 + 2e4dc80 + 19d128f + 1b9e4b2 + 1c46483 + fdda3f2 + 595fcd1 + 213395c + 8e514a8 + 2f30186 + bb4ed65 + 132d5b6 + 030ff33 + f2f20f3 + a50e133 + 4c554ee + dbfb1b8 + ccab83f + 00b350f + 78945d0 + f0e5f4b + ceb7d8c + 9e124d1 + 3de5912 + b6a974a + 10a6438 + cb6c1e7 + 18afd6c + 3baf1bd + c800904 + f52dcb8 + 126ccb2 + e7d6206 + e2d24ab + ec1abfc + 290ea90 + 9f4ca1b + edaa760 + c4c0c95 + d21f055 + 5b18029 + e6b97af + 010fb36 + 64c7b8d + 636523e + 4cc2cd6 + e34098a + 16367cd + 943c77f + 8226e5b + 0b47726 + 3cd8a03 + cc4782c + 9c653a6 + 656dbe5 + 9bce1ba + 7dc18ca + 861130d + 2d2ffbd + 4f413a5 + 2e1067a + 1d082e4 + e8aeb79 + b562091 + ff2fdc3 + 4aa72c0 + 1bb67ac + cd015c8 + 5e89910 + 0c21258 + dd54faf + 57f9063 + b88ce2e + af68643 + 06cd3b4 + 2c71b71 + ee02c35 + 9456314 + 5a77a7b + e98a077 + 738f2e6 + cb1e63c + 736df07 + d0a0154 + 990523c + 78687de + a5b6e79 + 6e9dfe9 + e201a1c + d9b45ef + 76222ad + 16d67da + 1ab2258 + b81d711 + ed2e9bc + 61efe82 + f353ea5 + 1f02519 + 58c1fe8 + ed502d9 + 2defba6 + 4885013 + 06a8384 + 17d9eed + 3b21b5d + c62101c + 909ef34 + 13d376a + 8a75367 + 98a3cf5 + 270f2c4 + 3038cfa + 1112202 + c8fb359 + 8d37cd0 + 4d868a7 + 555cb91 + 7ac5858 + 8103f1f + 9fe9c96 + a3ecac6 + 10e77c1 + e0d3e13 + 19ad608 + e0d665c + 1a5b402 + 56ae12a + 9073fc1 + 2d5b32f + f0e1784 commit 30eb247
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Hydrator/ClassMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ public function extract($object)
$attribute = $method;
if (preg_match('/^get/', $method)) {
$attribute = substr($method, 3);
$attribute = lcfirst($attribute);
if(!property_exists($object, $attribute)) {
$attribute = lcfirst($attribute);
}
}

if ($this->underscoreSeparatedKeys) {
Expand Down Expand Up @@ -185,5 +187,4 @@ public function hydrate(array $data, $object)

return $object;
}

}
52 changes: 52 additions & 0 deletions test/HydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Zend\Stdlib\Hydrator\ArraySerializable;
use Zend\Stdlib\Hydrator\Filter\FilterComposite;
use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCase;
use ZendTest\Stdlib\TestAsset\ClassMethodsTitleCase;
use ZendTest\Stdlib\TestAsset\ClassMethodsFilterProviderInterface;
use ZendTest\Stdlib\TestAsset\ClassMethodsMagicMethodSetter;
use ZendTest\Stdlib\TestAsset\ClassMethodsProtectedSetter;
Expand Down Expand Up @@ -44,6 +45,11 @@ class HydratorTest extends \PHPUnit_Framework_TestCase
*/
protected $classMethodsCamelCase;

/**
* @var ClassMethodsTitleCase
*/
protected $classMethodsTitleCase;

/**
* @var ClassMethodsCamelCaseMissing
*/
Expand All @@ -67,6 +73,7 @@ class HydratorTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->classMethodsCamelCase = new ClassMethodsCamelCase();
$this->classMethodsTitleCase = new ClassMethodsTitleCase();
$this->classMethodsCamelCaseMissing = new ClassMethodsCamelCaseMissing();
$this->classMethodsUnderscore = new ClassMethodsUnderscore();
$this->classMethodsInvalidParameter = new ClassMethodsInvalidParameter();
Expand All @@ -82,6 +89,12 @@ public function testInitiateValues()
$this->assertEquals($this->classMethodsCamelCase->isBar(), true);
$this->assertEquals($this->classMethodsCamelCase->getHasFoo(), true);
$this->assertEquals($this->classMethodsCamelCase->hasBar(), true);
$this->assertEquals($this->classMethodsTitleCase->getFooBar(), '1');
$this->assertEquals($this->classMethodsTitleCase->getFooBarBaz(), '2');
$this->assertEquals($this->classMethodsTitleCase->getIsFoo(), true);
$this->assertEquals($this->classMethodsTitleCase->getIsBar(), true);
$this->assertEquals($this->classMethodsTitleCase->getHasFoo(), true);
$this->assertEquals($this->classMethodsTitleCase->getHasBar(), true);
$this->assertEquals($this->classMethodsUnderscore->getFooBar(), '1');
$this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), '2');
$this->assertEquals($this->classMethodsUnderscore->getIsFoo(), true);
Expand Down Expand Up @@ -143,6 +156,45 @@ public function testHydratorClassMethodsCamelCase()
$this->assertEquals($test->hasBar(), false);
}



public function testHydratorClassMethodsTitleCase()
{
$hydrator = new ClassMethods(false);
$datas = $hydrator->extract($this->classMethodsTitleCase);
$this->assertTrue(isset($datas['FooBar']));
$this->assertEquals($datas['FooBar'], '1');
$this->assertTrue(isset($datas['FooBarBaz']));
$this->assertFalse(isset($datas['foo_bar']));
$this->assertTrue(isset($datas['IsFoo']));
$this->assertEquals($datas['IsFoo'], true);
$this->assertTrue(isset($datas['IsBar']));
$this->assertEquals($datas['IsBar'], true);
$this->assertTrue(isset($datas['HasFoo']));
$this->assertEquals($datas['HasFoo'], true);
$this->assertTrue(isset($datas['HasBar']));
$this->assertEquals($datas['HasBar'], true);
$test = $hydrator->hydrate(
array(
'FooBar' => 'foo',
'FooBarBaz' => 'bar',
'IsFoo' => false,
'IsBar' => false,
'HasFoo' => false,
'HasBar' => false,
),
$this->classMethodsTitleCase
);
$this->assertSame($this->classMethodsTitleCase, $test);
$this->assertEquals($test->getFooBar(), 'foo');
$this->assertEquals($test->getFooBarBaz(), 'bar');
$this->assertEquals($test->getIsFoo(), false);
$this->assertEquals($test->getIsBar(), false);
$this->assertEquals($test->getHasFoo(), false);
$this->assertEquals($test->getHasBar(), false);
}


public function testHydratorClassMethodsUnderscore()
{
$hydrator = new ClassMethods(true);
Expand Down
91 changes: 91 additions & 0 deletions test/TestAsset/ClassMethodsTitleCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

namespace ZendTest\Stdlib\TestAsset;

class ClassMethodsTitleCase
{
protected $FooBar = '1';

protected $FooBarBaz = '2';

protected $IsFoo = true;

protected $IsBar = true;

protected $HasFoo = true;

protected $HasBar = true;

public function getFooBar()
{
return $this->FooBar;
}

public function setFooBar($value)
{
$this->FooBar = $value;
return $this;
}

public function getFooBarBaz()
{
return $this->FooBarBaz;
}

public function setFooBarBaz($value)
{
$this->FooBarBaz = $value;
return $this;
}

public function getIsFoo()
{
return $this->IsFoo;
}

public function setIsFoo($IsFoo)
{
$this->IsFoo = $IsFoo;
return $this;
}

public function getIsBar()
{
return $this->IsBar;
}

public function setIsBar($IsBar)
{
$this->IsBar = $IsBar;
return $this;
}

public function getHasFoo()
{
return $this->HasFoo;
}

public function getHasBar()
{
return $this->HasBar;
}

public function setHasFoo($HasFoo)
{
$this->HasFoo = $HasFoo;
return $this;
}

public function setHasBar($HasBar)
{
$this->HasBar = $HasBar;
}
}

0 comments on commit 30eb247

Please sign in to comment.