1bf5586baffa7dc4305f23ce143279d0c2e85eb8
[yaffs-website] / vendor / symfony / serializer / Tests / Mapping / Loader / YamlFileLoaderTest.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\Loader;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Mapping\ClassMetadata;
16 use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
17 use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
18
19 /**
20  * @author Kévin Dunglas <dunglas@gmail.com>
21  */
22 class YamlFileLoaderTest extends TestCase
23 {
24     /**
25      * @var YamlFileLoader
26      */
27     private $loader;
28     /**
29      * @var ClassMetadata
30      */
31     private $metadata;
32
33     protected function setUp()
34     {
35         $this->loader = new YamlFileLoader(__DIR__.'/../../Fixtures/serialization.yml');
36         $this->metadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
37     }
38
39     public function testInterface()
40     {
41         $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Loader\LoaderInterface', $this->loader);
42     }
43
44     public function testLoadClassMetadataReturnsTrueIfSuccessful()
45     {
46         $this->assertTrue($this->loader->loadClassMetadata($this->metadata));
47     }
48
49     public function testLoadClassMetadataReturnsFalseWhenEmpty()
50     {
51         $loader = new YamlFileLoader(__DIR__.'/../../Fixtures/empty-mapping.yml');
52         $this->assertFalse($loader->loadClassMetadata($this->metadata));
53     }
54
55     /**
56      * @expectedException \Symfony\Component\Serializer\Exception\MappingException
57      */
58     public function testLoadClassMetadataReturnsThrowsInvalidMapping()
59     {
60         $loader = new YamlFileLoader(__DIR__.'/../../Fixtures/invalid-mapping.yml');
61         $loader->loadClassMetadata($this->metadata);
62     }
63
64     public function testLoadClassMetadata()
65     {
66         $this->loader->loadClassMetadata($this->metadata);
67
68         $this->assertEquals(TestClassMetadataFactory::createXmlCLassMetadata(), $this->metadata);
69     }
70
71     public function testMaxDepth()
72     {
73         $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy');
74         $this->loader->loadClassMetadata($classMetadata);
75
76         $attributesMetadata = $classMetadata->getAttributesMetadata();
77         $this->assertEquals(2, $attributesMetadata['foo']->getMaxDepth());
78         $this->assertEquals(3, $attributesMetadata['bar']->getMaxDepth());
79     }
80 }