Skip to content

Commit f7caef4

Browse files
committed
[Serializer][#18837] adding a test
1 parent 5e4cb91 commit f7caef4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Normalizer;
13+
14+
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
15+
16+
class AbstractObjectNormalizerTest extends \PHPUnit_Framework_TestCase
17+
{
18+
public function testDenormalize()
19+
{
20+
$normalizer = new AbstractObjectNormalizerDummy();
21+
$normalizedData = $normalizer->denormalize(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), __NAMESPACE__.'\Dummy');
22+
23+
$this->assertSame('foo', $normalizedData->foo);
24+
$this->assertNull($normalizedData->bar);
25+
$this->assertSame('baz', $normalizedData->baz);
26+
}
27+
}
28+
29+
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
30+
{
31+
protected function extractAttributes($object, $format = null, array $context = array())
32+
{
33+
}
34+
35+
protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
36+
{
37+
}
38+
39+
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
40+
{
41+
$object->$attribute = $value;
42+
}
43+
44+
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
45+
{
46+
return in_array($attribute, array('foo', 'baz'));
47+
}
48+
}
49+
50+
class Dummy
51+
{
52+
public $foo;
53+
public $bar;
54+
public $baz;
55+
}

0 commit comments

Comments
 (0)