ArrayNodeTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Symfony\Tests\Component\DependencyInjection\Configuration;
  3. use Symfony\Component\DependencyInjection\Configuration\ArrayNode;
  4. class ArrayNodeTest extends \PHPUnit_Framework_TestCase
  5. {
  6. /**
  7. * @expectedException Symfony\Component\DependencyInjection\Configuration\Exception\InvalidTypeException
  8. */
  9. public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
  10. {
  11. $node = new ArrayNode('root');
  12. $node->normalize(false);
  13. }
  14. /**
  15. * @expectedException InvalidArgumentException
  16. */
  17. public function testSetDefaultValueThrowsExceptionWhenNotAnArray()
  18. {
  19. $node = new ArrayNode('root');
  20. $node->setDefaultValue('test');
  21. }
  22. /**
  23. * @expectedException RuntimeException
  24. */
  25. public function testSetDefaultValueThrowsExceptionWhenNotAnPrototype()
  26. {
  27. $node = new ArrayNode('root');
  28. $node->setDefaultValue(array ('test'));
  29. }
  30. public function testGetDefaultValueReturnsAnEmptyArrayForPrototypes()
  31. {
  32. $node = new ArrayNode('root');
  33. $prototype = new ArrayNode(null, $node);
  34. $node->setPrototype($prototype);
  35. $this->assertEmpty($node->getDefaultValue());
  36. }
  37. public function testGetDefaultValueReturnsDefaultValueForPrototypes()
  38. {
  39. $node = new ArrayNode('root');
  40. $prototype = new ArrayNode(null, $node);
  41. $node->setPrototype($prototype);
  42. $node->setDefaultValue(array ('test'));
  43. $this->assertEquals(array ('test'), $node->getDefaultValue());
  44. }
  45. }