f435d36f744d25a45bdeac51c378837a96d19186
[yaffs-website] / serializer / Tests / Mapping / TestClassMetadataFactory.php
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\Mapping;
13
14 use Symfony\Component\Serializer\Mapping\AttributeMetadata;
15 use Symfony\Component\Serializer\Mapping\ClassMetadata;
16
17 /**
18  * @author Kévin Dunglas <dunglas@gmail.com>
19  */
20 class TestClassMetadataFactory
21 {
22     public static function createClassMetadata($withParent = false, $withInterface = false)
23     {
24         $expected = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
25
26         $foo = new AttributeMetadata('foo');
27         $foo->addGroup('a');
28         $expected->addAttributeMetadata($foo);
29
30         $bar = new AttributeMetadata('bar');
31         $bar->addGroup('b');
32         $bar->addGroup('c');
33         $bar->addGroup('name_converter');
34         $expected->addAttributeMetadata($bar);
35
36         $fooBar = new AttributeMetadata('fooBar');
37         $fooBar->addGroup('a');
38         $fooBar->addGroup('b');
39         $fooBar->addGroup('name_converter');
40         $expected->addAttributeMetadata($fooBar);
41
42         $symfony = new AttributeMetadata('symfony');
43         $expected->addAttributeMetadata($symfony);
44
45         if ($withParent) {
46             $kevin = new AttributeMetadata('kevin');
47             $kevin->addGroup('a');
48             $expected->addAttributeMetadata($kevin);
49
50             $coopTilleuls = new AttributeMetadata('coopTilleuls');
51             $coopTilleuls->addGroup('a');
52             $coopTilleuls->addGroup('b');
53             $expected->addAttributeMetadata($coopTilleuls);
54         }
55
56         if ($withInterface) {
57             $symfony->addGroup('a');
58             $symfony->addGroup('name_converter');
59         }
60
61         // load reflection class so that the comparison passes
62         $expected->getReflectionClass();
63
64         return $expected;
65     }
66
67     public static function createXmlCLassMetadata()
68     {
69         $expected = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
70
71         $foo = new AttributeMetadata('foo');
72         $foo->addGroup('group1');
73         $foo->addGroup('group2');
74         $expected->addAttributeMetadata($foo);
75
76         $bar = new AttributeMetadata('bar');
77         $bar->addGroup('group2');
78         $expected->addAttributeMetadata($bar);
79
80         return $expected;
81     }
82 }