This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #45
Showing
8 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
*/ | ||
class ClassMethodsTest extends TestCase | ||
{ | ||
use HydratorTestTrait; | ||
|
||
/** | ||
* @var ClassMethods | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Hydrator; | ||
|
||
use Zend\Hydrator\NamingStrategy\NamingStrategyInterface; | ||
use Zend\Hydrator\Strategy\StrategyInterface; | ||
use ZendTest\Hydrator\TestAsset\SimpleEntity; | ||
|
||
trait HydratorTestTrait | ||
{ | ||
public function testHydrateWithNamingStrategyAndStrategy() | ||
{ | ||
$namingStrategy = $this->createMock(NamingStrategyInterface::class); | ||
$namingStrategy | ||
->expects($this->any()) | ||
->method('hydrate') | ||
->with($this->anything()) | ||
->will($this->returnValue('value')) | ||
; | ||
|
||
$strategy = $this->createMock(StrategyInterface::class); | ||
$strategy | ||
->expects($this->any()) | ||
->method('hydrate') | ||
->with($this->anything()) | ||
->will($this->returnValue('hydrate')) | ||
; | ||
|
||
$this->hydrator->setNamingStrategy($namingStrategy); | ||
$this->hydrator->addStrategy('value', $strategy); | ||
|
||
$entity = $this->hydrator->hydrate(['foo_bar_baz' => 'blub'], new SimpleEntity()); | ||
$this->assertSame( | ||
'hydrate', | ||
$entity->getValue(), | ||
sprintf('Hydrator: %s', get_class($this->hydrator)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
*/ | ||
class ObjectPropertyTest extends TestCase | ||
{ | ||
use HydratorTestTrait; | ||
|
||
/** | ||
* @var ObjectProperty | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
*/ | ||
class ReflectionTest extends TestCase | ||
{ | ||
use HydratorTestTrait; | ||
|
||
/** | ||
* @var Reflection | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Hydrator\TestAsset; | ||
|
||
class SimpleEntity | ||
{ | ||
public $value; | ||
|
||
/** | ||
* @param mixed $value | ||
* @return void | ||
*/ | ||
public function setValue($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* Exchange internal values from provided array | ||
* | ||
* @param array $array | ||
* @return void | ||
*/ | ||
public function exchangeArray(array $array) | ||
{ | ||
if (array_key_exists('value', $array)) { | ||
$this->setValue($array['value']); | ||
} | ||
} | ||
|
||
/** | ||
* Return an array representation of the object | ||
* | ||
* @return array | ||
*/ | ||
public function getArrayCopy() | ||
{ | ||
return ['value' => $this->getValue()]; | ||
} | ||
} |