YamlFileLoaderTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Tests\Mapping\Loader;
  11. use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
  12. use Symfony\Component\Serializer\Mapping\ClassMetadata;
  13. use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
  14. /**
  15. * @author Kévin Dunglas <dunglas@gmail.com>
  16. */
  17. class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * @var YamlFileLoader
  21. */
  22. private $loader;
  23. /**
  24. * @var ClassMetadata
  25. */
  26. private $metadata;
  27. protected function setUp()
  28. {
  29. $this->loader = new YamlFileLoader(__DIR__.'/../../Fixtures/serialization.yml');
  30. $this->metadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  31. }
  32. public function testInterface()
  33. {
  34. $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Loader\LoaderInterface', $this->loader);
  35. }
  36. public function testLoadClassMetadataReturnsTrueIfSuccessful()
  37. {
  38. $this->assertTrue($this->loader->loadClassMetadata($this->metadata));
  39. }
  40. public function testLoadClassMetadataReturnsFalseWhenEmpty()
  41. {
  42. $loader = new YamlFileLoader(__DIR__.'/../../Fixtures/empty-mapping.yml');
  43. $this->assertFalse($loader->loadClassMetadata($this->metadata));
  44. }
  45. /**
  46. * @expectedException \Symfony\Component\Serializer\Exception\MappingException
  47. */
  48. public function testLoadClassMetadataReturnsThrowsInvalidMapping()
  49. {
  50. $loader = new YamlFileLoader(__DIR__.'/../../Fixtures/invalid-mapping.yml');
  51. $loader->loadClassMetadata($this->metadata);
  52. }
  53. public function testLoadClassMetadata()
  54. {
  55. $this->loader->loadClassMetadata($this->metadata);
  56. $this->assertEquals(TestClassMetadataFactory::createXmlCLassMetadata(), $this->metadata);
  57. }
  58. public function testMaxDepth()
  59. {
  60. $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy');
  61. $this->loader->loadClassMetadata($classMetadata);
  62. $attributesMetadata = $classMetadata->getAttributesMetadata();
  63. $this->assertEquals(2, $attributesMetadata['foo']->getMaxDepth());
  64. $this->assertEquals(3, $attributesMetadata['bar']->getMaxDepth());
  65. }
  66. }