Permalink
Browse files

Add unit tests for serializable strategy

Add unit tests for serializable strategy
  • Loading branch information...
1 parent e8e08e3 commit 441fc418260932a0e6a85f14b6d1f9dcd2c17112 @blanchonvincent blanchonvincent committed Aug 7, 2012
Showing with 53 additions and 0 deletions.
  1. +53 −0 tests/ZendTest/Stdlib/Strategy/SerializableStrategyTest.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
+
+namespace ZendTest\Stdlib\Strategy;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Stdlib\Hydrator\Strategy\SerializableStrategy;
+use Zend\Serializer\Serializer;
+
+class SerializableStrategyTest extends TestCase
+{
+ public function testCannotUseBadArgumentSerilizer()
+ {
+ $this->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException');
+ $serializerStrategy = new SerializableStrategy(false);
+ }
+
+ public function testUseBadSerilizerObject()
+ {
+ $serializer = Serializer::factory('phpserialize');
+ $serializerStrategy = new SerializableStrategy($serializer);
+ $this->assertEquals($serializer, $serializerStrategy->getSerializer());
+ }
+
+ public function testUseBadSerilizerString()
+ {
+ $serializerStrategy = new SerializableStrategy('phpserialize');
+ $this->assertEquals('Zend\Serializer\Adapter\PhpSerialize', get_class($serializerStrategy->getSerializer()));
+ }
+
+ public function testCanSerialize()
+ {
+ $serializer = Serializer::factory('phpserialize');
+ $serializerStrategy = new SerializableStrategy($serializer);
+ $serialized = $serializerStrategy->extract('foo');
+ $this->assertEquals($serialized, 's:3:"foo";');
+ }
+
+ public function testCanUnserialize()
+ {
+ $serializer = Serializer::factory('phpserialize');
+ $serializerStrategy = new SerializableStrategy($serializer);
+ $serialized = $serializerStrategy->hydrate('s:3:"foo";');
+ $this->assertEquals($serialized, 'foo');
+ }
+}

0 comments on commit 441fc41

Please sign in to comment.