Bladeren bron

Added test to the case of using virtual properties with exclusion policy set to "all".

Roger Llopart Pla 13 jaren geleden
bovenliggende
commit
bb53ce9562

+ 42 - 0
Tests/Fixtures/ObjectWithVirtualPropertiesAndExcludeAll.php

@@ -0,0 +1,42 @@
+<?php
+
+/*
+ * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace JMS\SerializerBundle\Tests\Fixtures;
+
+use JMS\SerializerBundle\Annotation\AccessorOrder;
+use JMS\SerializerBundle\Annotation\Type;
+use JMS\SerializerBundle\Annotation\VirtualProperty;
+use JMS\SerializerBundle\Annotation\SerializedName;
+use JMS\SerializerBundle\Annotation\Exclude;
+use JMS\SerializerBundle\Annotation\ExclusionPolicy;
+
+/**
+ * @AccessorOrder("custom", custom = {"prop_name", "existField", "foo" })
+ * @ExclusionPolicy("all")
+ */
+class ObjectWithVirtualPropertiesAndExcludeAll
+{
+    /**
+     * 
+     * @VirtualProperty
+     */
+    public function getVirtualValue()
+    {
+        return 'value';
+    }
+}

+ 13 - 0
Tests/Metadata/Driver/BaseDriverTest.php

@@ -94,5 +94,18 @@ abstract class BaseDriverTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($m->propertyMetadata['array']->xmlKeyValuePairs);
     }
 
+    public function testVirtualPropertyWithExcludeAll()
+    {
+        $a = new \JMS\SerializerBundle\Tests\Fixtures\ObjectWithVirtualPropertiesAndExcludeAll();
+        $m = $this->getDriver()->loadMetadataForClass(new \ReflectionClass($a));
+
+        $this->assertArrayHasKey('virtualValue', $m->propertyMetadata);
+
+        $p = new VirtualPropertyMetadata($m->name, 'virtualValue');
+        $p->getter = 'getVirtualValue';
+
+        $this->assertEquals($p, $m->propertyMetadata['virtualValue']);
+    }
+
     abstract protected function getDriver();
 }

+ 6 - 0
Tests/Metadata/Driver/xml/ObjectWithVirtualPropertiesAndExcludeAll.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<serializer>
+    <class name="JMS\SerializerBundle\Tests\Fixtures\ObjectWithVirtualPropertiesAndExcludeAll"  exclusion-policy="ALL">
+        <virtual-property method="getVirtualValue"/>
+    </class>
+</serializer>

+ 3 - 0
Tests/Metadata/Driver/yml/ObjectWithVirtualPropertiesAndExcludeAll.yml

@@ -0,0 +1,3 @@
+JMS\SerializerBundle\Tests\Fixtures\ObjectWithVirtualPropertiesAndExcludeAll:
+    virtual_properties:
+        getVirtualValue: ~