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

Commit

Permalink
Merge pull request #4919 from Ocramius/hotfix/reflection-hydrator-notice
Browse files Browse the repository at this point in the history
Notices being triggered when hydrating classes with no properties with the reflection hydrator
  • Loading branch information
weierophinney committed Aug 19, 2013
2 parents 98d2a07 + 47df877 commit c4c8c7a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/Zend/Stdlib/Hydrator/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ protected static function getReflProperties($input)
}

if (!isset(static::$reflProperties[$input])) {
$reflClass = new ReflectionClass($input);
$reflProperties = $reflClass->getProperties();
static::$reflProperties[$input] = array();
$reflClass = new ReflectionClass($input);
$reflProperties = $reflClass->getProperties();

foreach ($reflProperties as $property) {
$property->setAccessible(true);
Expand Down
47 changes: 47 additions & 0 deletions tests/ZendTest/Stdlib/Hydrator/ReflectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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
*/

namespace ZendTest\Stdlib\Hydrator;

use stdClass;
use Zend\Stdlib\Hydrator\Reflection;

/**
* Unit tests for {@see \Zend\Stdlib\Hydrator\Reflection}
*
* @covers \Zend\Stdlib\Hydrator\Reflection
* @group Zend_Stdlib
*/
class ReflectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Reflection
*/
protected $hydrator;

/**
* {@inheritDoc}
*/
public function setUp()
{
$this->hydrator = new Reflection();
}

public function testCanExtract()
{
$this->assertSame(array(), $this->hydrator->extract(new stdClass()));
}

public function testCanHydrate()
{
$object = new stdClass();

$this->assertSame($object, $this->hydrator->hydrate(array('foo' => 'bar'), $object));
}
}

0 comments on commit c4c8c7a

Please sign in to comment.