ArrayNodeTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\ExpressionLanguage\Tests\Node;
  11. use Symfony\Component\ExpressionLanguage\Node\ArrayNode;
  12. use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
  13. class ArrayNodeTest extends AbstractNodeTest
  14. {
  15. public function testSerialization()
  16. {
  17. $node = $this->createArrayNode();
  18. $node->addElement(new ConstantNode('foo'));
  19. $serializedNode = serialize($node);
  20. $unserializedNode = unserialize($serializedNode);
  21. $this->assertEquals($node, $unserializedNode);
  22. $this->assertNotEquals($this->createArrayNode(), $unserializedNode);
  23. }
  24. public function getEvaluateData()
  25. {
  26. return [
  27. [['b' => 'a', 'b'], $this->getArrayNode()],
  28. ];
  29. }
  30. public function getCompileData()
  31. {
  32. return [
  33. ['["b" => "a", 0 => "b"]', $this->getArrayNode()],
  34. ];
  35. }
  36. public function getDumpData()
  37. {
  38. yield ['{"b": "a", 0: "b"}', $this->getArrayNode()];
  39. $array = $this->createArrayNode();
  40. $array->addElement(new ConstantNode('c'), new ConstantNode('a"b'));
  41. $array->addElement(new ConstantNode('d'), new ConstantNode('a\b'));
  42. yield ['{"a\\"b": "c", "a\\\\b": "d"}', $array];
  43. $array = $this->createArrayNode();
  44. $array->addElement(new ConstantNode('c'));
  45. $array->addElement(new ConstantNode('d'));
  46. yield ['["c", "d"]', $array];
  47. }
  48. protected function getArrayNode()
  49. {
  50. $array = $this->createArrayNode();
  51. $array->addElement(new ConstantNode('a'), new ConstantNode('b'));
  52. $array->addElement(new ConstantNode('b'));
  53. return $array;
  54. }
  55. protected function createArrayNode()
  56. {
  57. return new ArrayNode();
  58. }
  59. }