-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from passkey1510/master
Add PropertyNamingStrategy
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/JMS/Serializer/Naming/IdenticalPropertyNamingStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 28 additions & 0 deletions
28
tests/JMS/Serializer/Tests/Serializer/Naming/IdenticalPropertyNamingStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |