Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add unit tests for serializable strategy

Add unit tests for serializable strategy
  • Loading branch information...
commit 441fc418260932a0e6a85f14b6d1f9dcd2c17112 1 parent e8e08e3
@blanchonvincent blanchonvincent authored
Showing with 53 additions and 0 deletions.
  1. +53 −0 tests/ZendTest/Stdlib/Strategy/SerializableStrategyTest.php
View
53 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');
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.