Forráskód Böngészése

added test to check order of properties and virtuals

Jaap van Otterdijk 12 éve
szülő
commit
a267745e6a

+ 38 - 0
tests/JMS/Serializer/Tests/Fixtures/AccessorOrderMethod.php

@@ -0,0 +1,38 @@
+<?php
+
+/*
+ * Copyright 2013 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\Serializer\Tests\Fixtures;
+
+use JMS\Serializer\Annotation as Serializer;
+
+/** @Serializer\AccessorOrder("custom",  custom = {"getC", "b", "a"}) */
+class AccessorOrderMethod
+{
+    private $b = 'b', $a = 'a';
+
+    /**
+     * @Serializer\VirtualProperty
+     * @Serializer\SerializedName("c")
+     *
+     * @return string
+     */
+    public function getC()
+    {
+        return 'c';
+    }
+}

+ 2 - 0
tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php

@@ -50,6 +50,7 @@ use JMS\Serializer\XmlSerializationVisitor;
 use JMS\Serializer\YamlSerializationVisitor;
 use JMS\Serializer\Tests\Fixtures\AccessorOrderChild;
 use JMS\Serializer\Tests\Fixtures\AccessorOrderParent;
+use JMS\Serializer\Tests\Fixtures\AccessorOrderMethod;
 use JMS\Serializer\Tests\Fixtures\Author;
 use JMS\Serializer\Tests\Fixtures\AuthorList;
 use JMS\Serializer\Tests\Fixtures\AuthorReadOnly;
@@ -549,6 +550,7 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->getContent('accessor_order_child'), $this->serialize(new AccessorOrderChild()));
         $this->assertEquals($this->getContent('accessor_order_parent'), $this->serialize(new AccessorOrderParent()));
+        $this->assertEquals($this->getContent('accessor_order_methods'), $this->serialize(new AccessorOrderMethod()));
     }
 
     public function testGroups()

+ 1 - 0
tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php

@@ -67,6 +67,7 @@ class JsonSerializationTest extends BaseSerializationTest
             $outputs['mixed_access_types'] = '{"id":1,"name":"Johannes","read_only_property":42}';
             $outputs['accessor_order_child'] = '{"c":"c","d":"d","a":"a","b":"b"}';
             $outputs['accessor_order_parent'] = '{"a":"a","b":"b"}';
+            $outputs['accessor_order_methods'] = '{"c":"c","b":"b","a":"a"}';
             $outputs['inline'] = '{"c":"c","a":"a","b":"b","d":"d"}';
             $outputs['groups_all'] = '{"foo":"foo","foobar":"foobar","bar":"bar","none":"none"}';
             $outputs['groups_foo'] = '{"foo":"foo","foobar":"foobar"}';

+ 6 - 0
tests/JMS/Serializer/Tests/Serializer/xml/accessor_order_methods.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<result>
+  <c><![CDATA[c]]></c>
+  <b><![CDATA[b]]></b>
+  <a><![CDATA[a]]></a>
+</result>

+ 3 - 0
tests/JMS/Serializer/Tests/Serializer/yml/accessor_order_methods.yml

@@ -0,0 +1,3 @@
+c: c
+b: b
+a: a