EnumNodeDefinitionTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Config\Tests\Definition\Builder;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
  13. class EnumNodeDefinitionTest extends TestCase
  14. {
  15. public function testWithOneValue()
  16. {
  17. $def = new EnumNodeDefinition('foo');
  18. $def->values(array('foo'));
  19. $node = $def->getNode();
  20. $this->assertEquals(array('foo'), $node->getValues());
  21. }
  22. public function testWithOneDistinctValue()
  23. {
  24. $def = new EnumNodeDefinition('foo');
  25. $def->values(array('foo', 'foo'));
  26. $node = $def->getNode();
  27. $this->assertEquals(array('foo'), $node->getValues());
  28. }
  29. /**
  30. * @expectedException \RuntimeException
  31. * @expectedExceptionMessage You must call ->values() on enum nodes.
  32. */
  33. public function testNoValuesPassed()
  34. {
  35. $def = new EnumNodeDefinition('foo');
  36. $def->getNode();
  37. }
  38. /**
  39. * @expectedException \InvalidArgumentException
  40. * @expectedExceptionMessage ->values() must be called with at least one value.
  41. */
  42. public function testWithNoValues()
  43. {
  44. $def = new EnumNodeDefinition('foo');
  45. $def->values(array());
  46. }
  47. public function testGetNode()
  48. {
  49. $def = new EnumNodeDefinition('foo');
  50. $def->values(array('foo', 'bar'));
  51. $node = $def->getNode();
  52. $this->assertEquals(array('foo', 'bar'), $node->getValues());
  53. }
  54. }