Browse Source

Merge pull request #37 from passkey1510/master

Add PropertyNamingStrategy
Johannes 12 years ago
parent
commit
f95ba241ba

+ 13 - 0
src/JMS/Serializer/Naming/IdenticalPropertyNamingStrategy.php

@@ -0,0 +1,13 @@
+<?php
+namespace JMS\Serializer\Naming;
+
+use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
+use JMS\Serializer\Metadata\PropertyMetadata;
+
+class IdenticalPropertyNamingStrategy implements PropertyNamingStrategyInterface
+{
+    public function translateName(PropertyMetadata $property)
+    {
+        return $property->name;
+    }
+}

+ 28 - 0
tests/JMS/Serializer/Tests/Serializer/Naming/IdenticalPropertyNamingStrategyTest.php

@@ -0,0 +1,28 @@
+<?php
+namespace JMS\Serializer\Tests\Serializer\Naming;
+
+use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
+
+class IdenticalPropertyNamingStrategyTest extends \PHPUnit_Framework_TestCase
+{
+    public function providePropertyNames()
+    {
+        return array(
+            array('createdAt'),
+            array('my_field'),
+            array('identical')
+        );
+    }
+
+    /**
+     * @dataProvider providePropertyNames
+     */
+    public function testTranslateName($propertyName)
+    {
+        $mockProperty = $this->getMockBuilder('JMS\Serializer\Metadata\PropertyMetadata')->disableOriginalConstructor()->getMock();
+        $mockProperty->name = $propertyName;
+
+        $strategy = new IdenticalPropertyNamingStrategy();
+        $this->assertEquals($propertyName, $strategy->translateName($mockProperty));
+    }
+}