浏览代码

updated performance test

Johannes Schmitt 14 年之前
父节点
当前提交
3e5d699e94
共有 2 个文件被更改,包括 20 次插入24 次删除
  1. 1 1
      Metadata/ClassHierarchyMetadata.php
  2. 19 23
      Tests/PerformanceTest.php

+ 1 - 1
Metadata/ClassHierarchyMetadata.php

@@ -21,7 +21,7 @@ class ClassHierarchyMetadata
         $time = 0;
 
         foreach ($this->classes as $class) {
-            if (false !== $filename = $class->getReflection()->getFilename()) {
+            if (false === $filename = $class->getReflection()->getFilename()) {
                 continue;
             }
 

+ 19 - 23
Tests/PerformanceTest.php

@@ -2,6 +2,14 @@
 
 namespace JMS\SerializerBundle\Tests;
 
+use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
+
+use JMS\SerializerBundle\JMSSerializerBundle;
+
+use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+
 use JMS\SerializerBundle\Tests\Fixtures\Comment;
 
 use JMS\SerializerBundle\Tests\Fixtures\Author;
@@ -61,33 +69,21 @@ class PerformanceTest extends \PHPUnit_Framework_TestCase
 
     private function getSerializer()
     {
-        $reader = new Reader();
-
-        $propertyNamingStrategy = new SerializedNameAnnotationStrategy(
-            $reader,
-            new CamelCaseNamingStrategy()
-        );
-
-        $encoders = array(
-            'xml'  => new XmlEncoder(),
-            'json' => new JsonEncoder(),
-        );
+        $container = new ContainerBuilder();
+        $container->set('annotation_reader', new Reader());
+        $extension = new JMSSerializerExtension();
+        $extension->load(array(array()), $container);
 
-        $customNormalizers = array(
-            new ArrayCollectionNormalizer(),
-        );
+        $bundle = new JMSSerializerBundle();
+        $bundle->build($container);
 
-        $exclusionStrategyFactory = new ExclusionStrategyFactory(array(
-            'ALL'  => new AllExclusionStrategy($reader),
-            'NONE' => new NoneExclusionStrategy($reader),
+        $container->getCompilerPassConfig()->setOptimizationPasses(array(
+            new ResolveDefinitionTemplatesPass(),
         ));
+        $container->getCompilerPassConfig()->setRemovingPasses(array());
+        $container->compile();
 
-        return new Serializer(
-            new NativePhpTypeNormalizer(),
-            new PropertyBasedNormalizer($reader, $propertyNamingStrategy, $exclusionStrategyFactory),
-            $customNormalizers,
-            $encoders
-        );
+        return $container->get('serializer');
     }
 
     private function printResults($test, $time, $iterations)