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

Commit

Permalink
Unit test for HydratorAwareInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
ghunti committed Apr 2, 2013
1 parent 0465a57 commit b08b5fe
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Zend\InputFilter\Factory as InputFilterFactory;
use Zend\Stdlib\Hydrator;
use ZendTest\Form\TestAsset\Entity;
use ZendTest\Form\TestAsset\HydratorAwareModel;

class FormTest extends TestCase
{
Expand Down Expand Up @@ -621,6 +622,20 @@ public function testUsesBoundObjectAsDataSourceWhenNoDataSet()
$this->assertTrue($this->form->isValid());
}

public function testUsesBoundObjectHydratorToPopulateForm()
{
$this->populateForm();
$object = new HydratorAwareModel();
$object->setFoo('fooValue');
$object->setBar('barValue');

$this->form->bind($object);
$foo = $this->form->get('foo');
$this->assertEquals('fooValue', $foo->getValue());
$bar = $this->form->get('bar');
$this->assertEquals('barValue', $bar->getValue());
}

public function testBindOnValidateIsTrueByDefault()
{
$this->assertTrue($this->form->bindOnValidate());
Expand Down
58 changes: 58 additions & 0 deletions tests/ZendTest/Form/TestAsset/HydratorAwareModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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_Form
*/

namespace ZendTest\Form\TestAsset;

use Zend\Stdlib\Hydrator\HydratorAwareInterface;
use Zend\Stdlib\Hydrator\HydratorInterface;
use Zend\Stdlib\Hydrator\ClassMethods;

class HydratorAwareModel implements HydratorAwareInterface
{
protected $hydrator = null;

protected $foo = null;
protected $bar = null;

public function setHydrator(HydratorInterface $hydrator)
{
$this->hydrator = $hydrator;
}

public function getHydrator()
{
if (!$this->hydrator) {
$this->hydrator = new ClassMethods();
}
return $this->hydrator;
}

public function setFoo($value)
{
$this->foo = $value;
return $this;
}

public function setBar($value)
{
$this->bar = $value;
return $this;
}

public function getFoo()
{
return $this->foo;
}

public function getBar()
{
return $this->bar;
}
}

0 comments on commit b08b5fe

Please sign in to comment.