8000 Add tests · symfony/symfony@3dac0f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dac0f8

Browse files
committed
Add tests
1 parent 95aae8d commit 3dac0f8

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Fixtures\Annotations;
13+
14+
use Symfony\Component\Serializer\Annotation\Groups;
15+
16+
/**
17+
* @Groups({"a"})
18+
*/
19+
class GroupClassDummy
20+
{
21+
private $foo;
22+
23+
private $bar;
24+
25+
public function getFoo()
26+
{
27+
return $this->foo;
28+
}
29+
30+
public function setFoo($foo): void
31+
{
32+
$this->foo = $foo;
33+
}
34+
35+
public function getBar()
36+
{
37+
return $this->bar;
38+
}
39+
40+
public function setBar($bar): void
41+
{
42+
$this->bar = $bar;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Fixtures\Attributes;
13+
14+
use Symfony\Component\Serializer\Annotation\Groups;
15+
16+
#[Groups('a')]
17+
class GroupClassDummy
18+
{
19+
private $foo;
20+
21+
private $bar;
22+
23+
public function getFoo()
24+
{
25+
return $this->foo;
26+
}
27+
28+
public function setFoo($foo): void
29+
{
30+
$this->foo = $foo;
31+
}
32+
33+
public function getBar()
34+
{
35+
return $this->bar;
36+
}
37+
38+
public function setBar($bar): void
39+
{
40+
$this->bar = $bar;
41+
}
42+
}

src/Symfony/Component/Serializer/Tests/SerializerTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummy;
5656
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummyFirstChild;
5757
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummySecondChild;
58+
use Symfony\Component\Serializer\Tests\Fixtures;
5859
use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux;
5960
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
6061
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
@@ -1228,6 +1229,36 @@ public function testNoCollectDenormalizationErrorsWithWrongEnum()
12281229
}
12291230
}
12301231

1232+
public function testGroupsOnClassSerialization()
1233+
{
1234+
$obj = new Fixtures\Attributes\GroupClassDummy();
1235+
$obj->setFoo("foo");
1236+
$obj->setBar("bar");
1237+
1238+
$obj2 = new Fixtures\Annotations\GroupClassDummy();
1239+
$obj2->setFoo("foo");
1240+
$obj2->setBar("bar");
1241+
1242+
$serializer = new Serializer(
1243+
[
1244+
new ObjectNormalizer()
1245+
],
1246+
[
1247+
'json' => new JsonEncoder()
1248+
]
1249+
);
1250+
1251+
$this->assertSame(
1252+
'{"foo":"foo","bar":"bar"}',
1253+
$serializer->serialize($obj, 'json', ['groups' => ['a']])
1254+
);
1255+
1256+
$this->assertSame(
1257+
'{"foo":"foo","bar":"bar"}',
1258+
$serializer->serialize($obj2, 'json', ['groups' => ['a']])
1259+
);
1260+
}
1261+
12311262
public static function provideCollectDenormalizationErrors()
12321263
{
12331264
return [

0 commit comments

Comments
 (0)
0