Jelajahi Sumber

Decoupled configuration of the custom handlers to be easier to extend serialization tests.

Deni 13 tahun lalu
induk
melakukan
597bc67a00
1 mengubah file dengan 24 tambahan dan 8 penghapusan
  1. 24 8
      Tests/Serializer/BaseSerializationTest.php

+ 24 - 8
Tests/Serializer/BaseSerializationTest.php

@@ -203,20 +203,16 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
 
     protected function getSerializer()
     {
-        $customHandlers = array();
-        $customHandlers[] = new DateTimeHandler();
-
-        $customDeserializationHandlers = $customHandlers;
-        $customDeserializationHandlers[] = new ArrayCollectionHandler();
-        $customDeserializationHandlers[] = new AuthorListDeserializationHandler();
+        $customSerializationHandlers = $this->getSerializationHandlers();
+        $customDeserializationHandlers = $this->getDeserializationHandlers();
 
         $factory = new MetadataFactory(new AnnotationDriver(new AnnotationReader()));
         $namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy());
         $objectConstructor = new UnserializeObjectConstructor();
 
         $serializationVisitors = array(
-            'json' => new JsonSerializationVisitor($namingStrategy, $customHandlers),
-            'xml'  => new XmlSerializationVisitor($namingStrategy, $customHandlers),
+            'json' => new JsonSerializationVisitor($namingStrategy, $customSerializationHandlers),
+            'xml'  => new XmlSerializationVisitor($namingStrategy, $customSerializationHandlers),
         );
         $deserializationVisitors = array(
             'json' => new JsonDeserializationVisitor($namingStrategy, $customDeserializationHandlers, $objectConstructor),
@@ -226,6 +222,26 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         return new Serializer($factory, $serializationVisitors, $deserializationVisitors);
     }
 
+    protected function getSerializationHandlers()
+    {
+        $handlers = array(
+            new DateTimeHandler()
+        );
+
+        return $handlers;
+    }
+
+    protected function getDeserializationHandlers()
+    {
+        $handlers = array(
+            new DateTimeHandler(),
+            new ArrayCollectionHandler(),
+            new AuthorListDeserializationHandler(),
+        );
+
+        return $handlers;
+    }
+
     private function getField($obj, $name)
     {
         $ref = new \ReflectionProperty($obj, $name);