From a1cfc9c6e30d618d1fa4c58c4049a4fce2e04dd2 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 16 Apr 2012 15:06:46 -0500 Subject: [PATCH 01/14] [zen-47] Form tests (mostly) complete - Complete except for test detailing that input filter from model will be used when model is InputFilterAware - Added Zend\Stdlib\ArraySerializableInterface - Added "Hydrator" subclass, per Marco Pivetta's suggestion, to allow arbitrary hydration of bound objects - Created two initial hydrator types: ObjectProperty (public properties of the object), ArraySerializable (classes implementing above mentioned ArraySerializableInterface) --- src/ArraySerializableInterface.php | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/ArraySerializableInterface.php diff --git a/src/ArraySerializableInterface.php b/src/ArraySerializableInterface.php new file mode 100644 index 000000000..8ca70e025 --- /dev/null +++ b/src/ArraySerializableInterface.php @@ -0,0 +1,43 @@ + Date: Tue, 17 Apr 2012 07:31:21 -0500 Subject: [PATCH 02/14] [zen-47] Tests run - but do not pass. :) - Ensured all interfaces are properly defined - Ensured all test assets are properly defined - Initial work on concrete Form class --- src/ArraySerializableInterface.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ArraySerializableInterface.php b/src/ArraySerializableInterface.php index 8ca70e025..d943e5774 100644 --- a/src/ArraySerializableInterface.php +++ b/src/ArraySerializableInterface.php @@ -18,6 +18,8 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ +namespace Zend\Stdlib; + /** * @category Zend * @package Zend_Stdlib From 6dac94a488730149eeff4881e41b2786ec939d0d Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 10 May 2012 12:03:34 -0500 Subject: [PATCH 03/14] [zen-12] Moved Hydrator from Form to Stdlib component - Not necessarily specific to forms --- src/Hydrator/ArraySerializable.php | 55 ++++++++++++++++++++++++++++++ src/Hydrator/HydratorInterface.php | 41 ++++++++++++++++++++++ src/Hydrator/ObjectProperty.php | 50 +++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/Hydrator/ArraySerializable.php create mode 100644 src/Hydrator/HydratorInterface.php create mode 100644 src/Hydrator/ObjectProperty.php diff --git a/src/Hydrator/ArraySerializable.php b/src/Hydrator/ArraySerializable.php new file mode 100644 index 000000000..0f0ed759e --- /dev/null +++ b/src/Hydrator/ArraySerializable.php @@ -0,0 +1,55 @@ +exchangeArray($data); + } +} diff --git a/src/Hydrator/HydratorInterface.php b/src/Hydrator/HydratorInterface.php new file mode 100644 index 000000000..37422bc65 --- /dev/null +++ b/src/Hydrator/HydratorInterface.php @@ -0,0 +1,41 @@ + $value) { + $object->$property = $value; + } + } +} From 49a62184fe51212d6b7f6bc6ce7d112e0eb7beaa Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 10 May 2012 15:40:51 -0500 Subject: [PATCH 04/14] [zen-12] Bi-directional bind support - HydratorInterface now defines extract($object), expecting it to return an array of data - BaseForm::bind() now extracts data from the object and uses it to populateValues() - todo: use bound data as data for validation if setData() has not been called --- src/Hydrator/ArraySerializable.php | 20 ++++++++++++++++++++ src/Hydrator/HydratorInterface.php | 8 ++++++++ src/Hydrator/ObjectProperty.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/Hydrator/ArraySerializable.php b/src/Hydrator/ArraySerializable.php index 0f0ed759e..6580debee 100644 --- a/src/Hydrator/ArraySerializable.php +++ b/src/Hydrator/ArraySerializable.php @@ -32,6 +32,26 @@ */ class ArraySerializable implements HydratorInterface { + /** + * Extract values from the provided object + * + * Extracts values via the object's getArrayCopy() method. + * + * @param object $object + * @return array + * @throws Exception\BadMethodCallException for an $object not implementing getArrayCopy() + */ + public function extract($object) + { + if (!is_callable(array($object, 'getArrayCopy'))) { + throw new Exception\BadMethodCallException(sprintf( + '%s expects the provided object to implement getArrayCopy()', + __METHOD__ + )); + } + return $object->getArrayCopy(); + } + /** * Hydrate an object the implements the exchangeArray() method * diff --git a/src/Hydrator/HydratorInterface.php b/src/Hydrator/HydratorInterface.php index 37422bc65..1f5d7840e 100644 --- a/src/Hydrator/HydratorInterface.php +++ b/src/Hydrator/HydratorInterface.php @@ -30,6 +30,14 @@ */ interface HydratorInterface { + /** + * Extract values from an object + * + * @param object $object + * @return array + */ + public function extract($object); + /** * Hydrate $object with the provided $data. * diff --git a/src/Hydrator/ObjectProperty.php b/src/Hydrator/ObjectProperty.php index 838359251..d3b4ee974 100644 --- a/src/Hydrator/ObjectProperty.php +++ b/src/Hydrator/ObjectProperty.php @@ -32,6 +32,27 @@ */ class ObjectProperty implements HydratorInterface { + /** + * Extract values from an object + * + * Extracts the accessible non-static properties of the given $object. + * + * @param object $object + * @return array + * @throws Exception\BadMethodCallException for a non-object $object + */ + public function extract($object) + { + if (!is_object($object)) { + throw new Exception\BadMethodCallException(sprintf( + '%s expects the provided $object to be a PHP object)', + __METHOD__ + )); + } + + return get_object_vars($object); + } + /** * Hydrate an object by populating public properties * @@ -40,9 +61,16 @@ class ObjectProperty implements HydratorInterface * @param array $data * @param object $object * @return void + * @throws Exception\BadMethodCallException for a non-object $object */ public function hydrate(array $data, $object) { + if (!is_object($object)) { + throw new Exception\BadMethodCallException(sprintf( + '%s expects the provided $object to be a PHP object)', + __METHOD__ + )); + } foreach ($data as $property => $value) { $object->$property = $value; } From cb7a78743db4383706f7a5bd1129524320402e7f Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 10 May 2012 16:35:18 -0500 Subject: [PATCH 05/14] [zen-12] allow using populate() - Allows it to work with Zend\Db row population --- src/Hydrator/ArraySerializable.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Hydrator/ArraySerializable.php b/src/Hydrator/ArraySerializable.php index 6580debee..75ac24340 100644 --- a/src/Hydrator/ArraySerializable.php +++ b/src/Hydrator/ArraySerializable.php @@ -53,23 +53,32 @@ public function extract($object) } /** - * Hydrate an object the implements the exchangeArray() method + * Hydrate an object * - * Hydrates an object by passing $data to its exchangeArray() method. + * Hydrates an object by passing $data to either its exchangeArray() or + * populate() method. * * @param array $data * @param object $object * @return void - * @throws Exception\BadMethodCallException for an $object not implementing exchangeArray() + * @throws Exception\BadMethodCallException for an $object not implementing exchangeArray() or populate() */ public function hydrate(array $data, $object) { - if (!is_callable(array($object, 'exchangeArray'))) { + if (!is_callable(array($object, 'exchangeArray')) + && !is_callable(array($object, 'populate')) + ) { throw new Exception\BadMethodCallException(sprintf( - '%s expects the provided object to implement exchangeArray()', + '%s expects the provided object to implement exchangeArray() or populate()', __METHOD__ )); } - $object->exchangeArray($data); + + if (is_callable(array($object, 'exchangeArray'))) { + $object->exchangeArray($data); + return; + } + + $object->populate($data); } } From 50bab1651133807d270b2d508c7d424bcb836393 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 08:17:31 -0500 Subject: [PATCH 06/14] [zen-12] Removed Dojo from test suite - Dojo integration largely relied on integration with Zend\Form; removing from testing for now, as it has not been refactored to work with the new Zend\Form code. --- .travis/skipped-components | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/skipped-components b/.travis/skipped-components index 31bcaa87f..171dfe9d7 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,5 +1,6 @@ Zend/Amf Zend/Date +Zend/Dojo Zend/Queue Zend/Service Zend/Test From 2e9688e2db94cd0adb28081a20e0d14defd73658 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 18 May 2012 00:22:37 +0200 Subject: [PATCH 07/14] [Travis] Enable Zend\Math tests --- .travis/tested-components | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/tested-components b/.travis/tested-components index b1f4a794d..9b338206b 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -29,6 +29,7 @@ Zend/Locale Zend/Log Zend/Mail Zend/Markup +Zend/Math Zend/Measure Zend/Memory Zend/Mime From fff81c761a6e403042c9033bd6a17dd64b4f049b Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Fri, 18 May 2012 00:58:35 +0200 Subject: [PATCH 08/14] bad first commit add value for property, bad first commit --- src/Hydrator/ClassMethods.php | 22 ++++++++++------------ test/HydratorTest.php | 14 ++++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Hydrator/ClassMethods.php b/src/Hydrator/ClassMethods.php index a2339f67d..9eccfaa33 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -65,23 +65,21 @@ public function extract($object) )); } - $attributes = array(); - $methods = get_class_methods($object); - foreach($methods as $method) { - if(preg_match('/^set[A-Z]{1}\w*/', $method)) { - $attributes[] = substr($method, 3); - } - } - $transform = function($letters) { $letter = array_shift($letters); return '_' . strtolower($letter); }; - foreach($attributes as &$attribute) { - $attribute = lcfirst($attribute); - if (!$this->useCamelCase) { - $attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute); + $attributes = array(); + $methods = get_class_methods($object); + foreach($methods as $method) { + if(preg_match('/^get[A-Z]{1}\w*/', $method)) { + $attribute = substr($method, 3); + $attribute = lcfirst($attribute); + if (!$this->useCamelCase) { + $attribute = preg_replace_callback('/([A-Z])/', $transform, $attribute); + } + $attributes[$attribute] = $object->$method(); } } diff --git a/test/HydratorTest.php b/test/HydratorTest.php index f5b770ec9..2d989b624 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -52,9 +52,10 @@ public function testHydratorClassMethodsCamelCase() { $hydrator = new ClassMethods(true); $datas = $hydrator->extract($this->classMethodsCamelCase); - $this->assertTrue(in_array('fooBar', $datas)); - $this->assertTrue(in_array('fooBarBaz', $datas)); - $this->assertFalse(in_array('foo_bar', $datas)); + $this->assertTrue(isset($datas['fooBar'])); + $this->assertEquals($datas['fooBar'], '1'); + $this->assertTrue(isset($datas['fooBarBaz'])); + $this->assertFalse(isset($datas['foo_bar'])); $hydrator->hydrate(array('fooBar' => 'foo', 'fooBarBaz' => 'bar'), $this->classMethodsCamelCase); $this->assertEquals($this->classMethodsCamelCase->getFooBar(), 'foo'); $this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), 'bar'); @@ -64,9 +65,10 @@ public function testHydratorClassMethodsUnderscore() { $hydrator = new ClassMethods(false); $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertTrue(in_array('foo_bar', $datas)); - $this->assertTrue(in_array('foo_bar_baz', $datas)); - $this->assertFalse(in_array('fooBar', $datas)); + $this->assertTrue(isset($datas['foo_bar'])); + $this->assertEquals($datas['foo_bar'], '1'); + $this->assertTrue(isset($datas['foo_bar_baz'])); + $this->assertFalse(isset($datas['fooBar'])); $hydrator->hydrate(array('foo_bar' => 'foo', 'foo_bar_baz' => 'bar'), $this->classMethodsUnderscore); $this->assertEquals($this->classMethodsUnderscore->getFooBar(), 'foo'); $this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), 'bar'); From 981242a3be1412964e54e4d1cde8e9f980335a77 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Fri, 18 May 2012 01:06:31 +0200 Subject: [PATCH 09/14] add setter verification add setter verification in attributes extract --- src/Hydrator/ClassMethods.php | 5 +++ test/HydratorTest.php | 19 +++++++++- .../ClassMethodsCamelCaseMissing.php | 36 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/TestAsset/ClassMethodsCamelCaseMissing.php diff --git a/src/Hydrator/ClassMethods.php b/src/Hydrator/ClassMethods.php index 9eccfaa33..025433001 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -74,6 +74,11 @@ public function extract($object) $methods = get_class_methods($object); foreach($methods as $method) { if(preg_match('/^get[A-Z]{1}\w*/', $method)) { + // setter verification + $setter = preg_replace('/^get/', 'set', $method); + if(!in_array($setter, $methods)) { + continue; + } $attribute = substr($method, 3); $attribute = lcfirst($attribute); if (!$this->useCamelCase) { diff --git a/test/HydratorTest.php b/test/HydratorTest.php index 2d989b624..8c7ab1c17 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -24,7 +24,8 @@ use Zend\Stdlib\Hydrator\ClassMethods; use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCase, - ZendTest\Stdlib\TestAsset\ClassMethodsUnderscore; + ZendTest\Stdlib\TestAsset\ClassMethodsUnderscore, + ZendTest\Stdlib\TestAsset\ClassMethodsCamelCaseMissing; /** * @category Zend @@ -39,6 +40,7 @@ class HydratorTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->classMethodsCamelCase = new ClassMethodsCamelCase(); + $this->classMethodsCamelCaseMissing = new ClassMethodsCamelCaseMissing(); $this->classMethodsUnderscore = new ClassMethodsUnderscore(); } @@ -46,6 +48,8 @@ public function testInitiateValues() { $this->assertEquals($this->classMethodsCamelCase->getFooBar(), '1'); $this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), '2'); + $this->assertEquals($this->classMethodsUnderscore->getFooBar(), '1'); + $this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), '2'); } public function testHydratorClassMethodsCamelCase() @@ -61,6 +65,19 @@ public function testHydratorClassMethodsCamelCase() $this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), 'bar'); } + public function testHydratorClassMethodsCamelCaseWithSetterMissing() + { + $hydrator = new ClassMethods(true); + $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'])); + $hydrator->hydrate(array('fooBar' => 'foo'), $this->classMethodsCamelCaseMissing); + $this->assertEquals($this->classMethodsCamelCaseMissing->getFooBar(), 'foo'); + $this->assertEquals($this->classMethodsCamelCaseMissing->getFooBarBaz(), '2'); + } + public function testHydratorClassMethodsUnderscore() { $hydrator = new ClassMethods(false); diff --git a/test/TestAsset/ClassMethodsCamelCaseMissing.php b/test/TestAsset/ClassMethodsCamelCaseMissing.php new file mode 100644 index 000000000..03ffb4ee4 --- /dev/null +++ b/test/TestAsset/ClassMethodsCamelCaseMissing.php @@ -0,0 +1,36 @@ +fooBar; + } + + public function setFooBar($value) + { + $this->fooBar = $value; + return $this; + } + + public function getFooBarBaz() + { + return $this->fooBarBaz; + } + + /* + * comment to detection verification + * + public function setFooBarBaz($value) + { + $this->fooBarBaz = $value; + return $this; + } + */ +} \ No newline at end of file From 6790e1fe3492a69f716b1606f120534cf99557ff Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Fri, 18 May 2012 01:11:20 +0200 Subject: [PATCH 10/14] update doc update doc & remove useless parameter regex --- src/Hydrator/ClassMethods.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Hydrator/ClassMethods.php b/src/Hydrator/ClassMethods.php index 025433001..294e6339b 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -48,7 +48,7 @@ public function __construct($useCamelCase = true) } /** - * Extract values from an object + * Extract values from an object with class methods * * Extracts the getter/setter of the given $object. * @@ -73,7 +73,7 @@ public function extract($object) $attributes = array(); $methods = get_class_methods($object); foreach($methods as $method) { - if(preg_match('/^get[A-Z]{1}\w*/', $method)) { + if(preg_match('/^get[A-Z]\w*/', $method)) { // setter verification $setter = preg_replace('/^get/', 'set', $method); if(!in_array($setter, $methods)) { @@ -92,7 +92,7 @@ public function extract($object) } /** - * Hydrate an object by populating public properties + * Hydrate an object by populating getter/setter methods * * Hydrates an object by getter/setter methods of the object. * From 8074ba031d23ae588ced15737cf3d95c7e8cb5a2 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 22 May 2012 11:11:46 -0500 Subject: [PATCH 11/14] Fix API doc - s/CameCase/CamelCase/ --- 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 294e6339b..1398ed00d 100644 --- a/src/Hydrator/ClassMethods.php +++ b/src/Hydrator/ClassMethods.php @@ -33,7 +33,7 @@ class ClassMethods implements HydratorInterface { /** - * CameCase usage to extract attribute with getter/setter method name + * CamelCase usage to extract attribute with getter/setter method name * @var boolean */ protected $useCamelCase; From 910768ea5a4fcacab4b3c6d72fee5d2af2695771 Mon Sep 17 00:00:00 2001 From: prolic Date: Mon, 28 May 2012 15:21:01 +0200 Subject: [PATCH 12/14] adjusted api usage in unit tests --- test/HydratorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/HydratorTest.php b/test/HydratorTest.php index 8c7ab1c17..b32b17d53 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -60,7 +60,7 @@ public function testHydratorClassMethodsCamelCase() $this->assertEquals($datas['fooBar'], '1'); $this->assertTrue(isset($datas['fooBarBaz'])); $this->assertFalse(isset($datas['foo_bar'])); - $hydrator->hydrate(array('fooBar' => 'foo', 'fooBarBaz' => 'bar'), $this->classMethodsCamelCase); + $this->classMethodsCamelCase = $hydrator->hydrate(array('fooBar' => 'foo', 'fooBarBaz' => 'bar'), $this->classMethodsCamelCase); $this->assertEquals($this->classMethodsCamelCase->getFooBar(), 'foo'); $this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), 'bar'); } @@ -73,7 +73,7 @@ public function testHydratorClassMethodsCamelCaseWithSetterMissing() $this->assertEquals($datas['fooBar'], '1'); $this->assertFalse(isset($datas['fooBarBaz'])); $this->assertFalse(isset($datas['foo_bar'])); - $hydrator->hydrate(array('fooBar' => 'foo'), $this->classMethodsCamelCaseMissing); + $this->classMethodsCamelCaseMissing = $hydrator->hydrate(array('fooBar' => 'foo'), $this->classMethodsCamelCaseMissing); $this->assertEquals($this->classMethodsCamelCaseMissing->getFooBar(), 'foo'); $this->assertEquals($this->classMethodsCamelCaseMissing->getFooBarBaz(), '2'); } @@ -86,7 +86,7 @@ public function testHydratorClassMethodsUnderscore() $this->assertEquals($datas['foo_bar'], '1'); $this->assertTrue(isset($datas['foo_bar_baz'])); $this->assertFalse(isset($datas['fooBar'])); - $hydrator->hydrate(array('foo_bar' => 'foo', 'foo_bar_baz' => 'bar'), $this->classMethodsUnderscore); + $this->classMethodsUnderscore = $hydrator->hydrate(array('foo_bar' => 'foo', 'foo_bar_baz' => 'bar'), $this->classMethodsUnderscore); $this->assertEquals($this->classMethodsUnderscore->getFooBar(), 'foo'); $this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), 'bar'); } From 79bbc9f6890ed969a001399a89c403bcd96aa052 Mon Sep 17 00:00:00 2001 From: prolic Date: Tue, 29 May 2012 15:36:24 +0200 Subject: [PATCH 13/14] fix in Hydrator\ArraySerializable --- src/Hydrator/ArraySerializable.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Hydrator/ArraySerializable.php b/src/Hydrator/ArraySerializable.php index d5623522a..da5ed9c61 100644 --- a/src/Hydrator/ArraySerializable.php +++ b/src/Hydrator/ArraySerializable.php @@ -67,10 +67,8 @@ public function hydrate(array $data, $object) { if (is_callable(array($object, 'exchangeArray'))) { $object->exchangeArray($data); - return; } else if (is_callable(array($object, 'populate'))) { $object->populate($data); - return; } else { throw new Exception\BadMethodCallException(sprintf( '%s expects the provided object to implement exchangeArray() or populate()', From 84099777f67d8ab0028aa71e3445e3afb02d02a6 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 30 May 2012 11:42:21 -0500 Subject: [PATCH 14/14] [zendframework/zf2#1388] Added assertSame assertions - Capture results of hydrate() to local variable - Assert local variable is same as hydrated object - Do further assertions against local variable --- test/HydratorTest.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/HydratorTest.php b/test/HydratorTest.php index b32b17d53..0d8afab8f 100644 --- a/test/HydratorTest.php +++ b/test/HydratorTest.php @@ -60,9 +60,10 @@ public function testHydratorClassMethodsCamelCase() $this->assertEquals($datas['fooBar'], '1'); $this->assertTrue(isset($datas['fooBarBaz'])); $this->assertFalse(isset($datas['foo_bar'])); - $this->classMethodsCamelCase = $hydrator->hydrate(array('fooBar' => 'foo', 'fooBarBaz' => 'bar'), $this->classMethodsCamelCase); - $this->assertEquals($this->classMethodsCamelCase->getFooBar(), 'foo'); - $this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), 'bar'); + $test = $hydrator->hydrate(array('fooBar' => 'foo', 'fooBarBaz' => 'bar'), $this->classMethodsCamelCase); + $this->assertSame($this->classMethodsCamelCase, $test); + $this->assertEquals($test->getFooBar(), 'foo'); + $this->assertEquals($test->getFooBarBaz(), 'bar'); } public function testHydratorClassMethodsCamelCaseWithSetterMissing() @@ -73,9 +74,10 @@ public function testHydratorClassMethodsCamelCaseWithSetterMissing() $this->assertEquals($datas['fooBar'], '1'); $this->assertFalse(isset($datas['fooBarBaz'])); $this->assertFalse(isset($datas['foo_bar'])); - $this->classMethodsCamelCaseMissing = $hydrator->hydrate(array('fooBar' => 'foo'), $this->classMethodsCamelCaseMissing); - $this->assertEquals($this->classMethodsCamelCaseMissing->getFooBar(), 'foo'); - $this->assertEquals($this->classMethodsCamelCaseMissing->getFooBarBaz(), '2'); + $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() @@ -86,8 +88,9 @@ public function testHydratorClassMethodsUnderscore() $this->assertEquals($datas['foo_bar'], '1'); $this->assertTrue(isset($datas['foo_bar_baz'])); $this->assertFalse(isset($datas['fooBar'])); - $this->classMethodsUnderscore = $hydrator->hydrate(array('foo_bar' => 'foo', 'foo_bar_baz' => 'bar'), $this->classMethodsUnderscore); - $this->assertEquals($this->classMethodsUnderscore->getFooBar(), 'foo'); - $this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), 'bar'); + $test = $hydrator->hydrate(array('foo_bar' => 'foo', 'foo_bar_baz' => 'bar'), $this->classMethodsUnderscore); + $this->assertSame($this->classMethodsUnderscore, $test); + $this->assertEquals($test->getFooBar(), 'foo'); + $this->assertEquals($test->getFooBarBaz(), 'bar'); } }