Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hydrator aware trait #4751

Merged
merged 2 commits into from

3 participants

@mouhamed

Basic implementation of HydratorAwareInterface as a trait

@coveralls

Coverage Status

Coverage remained the same when pulling 83e5c3e on mouhamed:hydrator-aware-trait into 22554c4 on zendframework:develop.

@weierophinney weierophinney was assigned
@weierophinney weierophinney merged commit 83e5c3e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
49 library/Zend/Stdlib/Hydrator/HydratorAwareTrait.php
@@ -0,0 +1,49 @@
+<?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 Zend\Stdlib\Hydrator;
+
+use Zend\Stdlib\hydrator\HydratorInterface;
+
+trait HydratorAwareTrait
+{
+ /**
+ * Hydrator instance
+ *
+ * @var HydratorInterface
+ * @access protected
+ */
+ protected $hydrator = null;
+
+ /**
+ * Set hydrator
+ *
+ * @param HydratorInterface $hydrator
+ * @return self
+ * @access public
+ */
+ public function setHydrator(HydratorInterface $hydrator)
+ {
+ $this->hydrator = $hydrator;
+
+ return $this;
+ }
+
+ /**
+ * Retrieve hydrator
+ *
+ * @param void
+ * @return null|HydratorInterface
+ * @access public
+ */
+ public function getHydrator()
+ {
+ return $this->hydrator;
+ }
+}
View
45 tests/ZendTest/Stdlib/Hydrator/HydratorAwareTraitTest.php
@@ -0,0 +1,45 @@
+<?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_Hydrator
+ */
+
+namespace ZendTest\Stdlib\Hydrator;
+
+use \PHPUnit_Framework_TestCase as TestCase;
+
+/**
+ * @requires PHP 5.4
+ */
+class HydratorAwareTraitTest extends TestCase
+{
+ public function testSetHydrator()
+ {
+ $object = $this->getObjectForTrait('\Zend\Stdlib\Hydrator\HydratorAwareTrait');
+
+ $this->assertAttributeEquals(null, 'hydrator', $object);
+
+ $hydrator = $this->getMockForAbstractClass('\Zend\Stdlib\Hydrator\AbstractHydrator');
+
+ $object->setHydrator($hydrator);
+
+ $this->assertAttributeEquals($hydrator, 'hydrator', $object);
+ }
+
+ public function testGetHydrator()
+ {
+ $object = $this->getObjectForTrait('\Zend\Stdlib\Hydrator\HydratorAwareTrait');
+
+ $this->assertNull($object->getHydrator());
+
+ $hydrator = $this->getMockForAbstractClass('\Zend\Stdlib\Hydrator\AbstractHydrator');
+
+ $object->setHydrator($hydrator);
+
+ $this->assertEquals($hydrator, $object->getHydrator());
+ }
+}
Something went wrong with that request. Please try again.