YamlSerializationTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace JMS\Serializer\Tests\Serializer;
  3. use JMS\Serializer\Exception\RuntimeException;
  4. use JMS\Serializer\SerializationContext;
  5. class YamlSerializationTest extends BaseSerializationTest
  6. {
  7. public function testObjectUsingTypeCasting()
  8. {
  9. $this->markTestSkipped('This is not available for the YAML format.');
  10. }
  11. public function testEmptyChild()
  12. {
  13. $this->markTestSkipped('This is not available for the YAML format.');
  14. }
  15. public function testSkipEmptyChild()
  16. {
  17. $this->markTestSkipped('This is not available for the YAML format.');
  18. }
  19. public function testConstraintViolation()
  20. {
  21. $this->markTestSkipped('This is not available for the YAML format.');
  22. }
  23. public function testConstraintViolationList()
  24. {
  25. $this->markTestSkipped('This is not available for the YAML format.');
  26. }
  27. public function testFormErrors()
  28. {
  29. $this->markTestSkipped('This is not available for the YAML format.');
  30. }
  31. public function testNestedFormErrors()
  32. {
  33. $this->markTestSkipped('This is not available for the YAML format.');
  34. }
  35. public function testFormErrorsWithNonFormComponents()
  36. {
  37. $this->markTestSkipped('This is not available for the YAML format.');
  38. }
  39. protected function getContent($key)
  40. {
  41. if (!file_exists($file = __DIR__ . '/yml/' . $key . '.yml')) {
  42. throw new RuntimeException(sprintf('The content with key "%s" does not exist.', $key));
  43. }
  44. return file_get_contents($file);
  45. }
  46. public function getTypeHintedArrays()
  47. {
  48. return [
  49. [[1, 2], "- 1\n- 2\n", null],
  50. [['a', 'b'], "- a\n- b\n", null],
  51. [['a' => 'a', 'b' => 'b'], "a: a\nb: b\n", null],
  52. [[], " []\n", null],
  53. [[], " []\n", SerializationContext::create()->setInitialType('array')],
  54. [[], " []\n", SerializationContext::create()->setInitialType('array<integer>')],
  55. [[], " {}\n", SerializationContext::create()->setInitialType('array<string,integer>')],
  56. [[1, 2], "- 1\n- 2\n", SerializationContext::create()->setInitialType('array')],
  57. [[1 => 1, 2 => 2], "1: 1\n2: 2\n", SerializationContext::create()->setInitialType('array')],
  58. [[1 => 1, 2 => 2], "- 1\n- 2\n", SerializationContext::create()->setInitialType('array<integer>')],
  59. [['a', 'b'], "- a\n- b\n", SerializationContext::create()->setInitialType('array<string>')],
  60. [[1 => 'a', 2 => 'b'], "- a\n- b\n", SerializationContext::create()->setInitialType('array<string>')],
  61. [['a' => 'a', 'b' => 'b'], "- a\n- b\n", SerializationContext::create()->setInitialType('array<string>')],
  62. [[1, 2], "0: 1\n1: 2\n", SerializationContext::create()->setInitialType('array<integer,integer>')],
  63. [[1, 2], "0: 1\n1: 2\n", SerializationContext::create()->setInitialType('array<string,integer>')],
  64. [[1, 2], "0: 1\n1: 2\n", SerializationContext::create()->setInitialType('array<string,string>')],
  65. [['a', 'b'], "0: a\n1: b\n", SerializationContext::create()->setInitialType('array<integer,string>')],
  66. [['a' => 'a', 'b' => 'b'], "a: a\nb: b\n", SerializationContext::create()->setInitialType('array<string,string>')],
  67. ];
  68. }
  69. /**
  70. * @dataProvider getTypeHintedArrays
  71. * @param array $array
  72. * @param string $expected
  73. * @param SerializationContext|null $context
  74. */
  75. public function testTypeHintedArraySerialization(array $array, $expected, $context = null)
  76. {
  77. $this->assertEquals($expected, $this->serialize($array, $context));
  78. }
  79. protected function getFormat()
  80. {
  81. return 'yml';
  82. }
  83. protected function hasDeserializer()
  84. {
  85. return false;
  86. }
  87. }