EnumNodeTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\EnumNode;
  13. class EnumNodeTest extends TestCase
  14. {
  15. public function testFinalizeValue()
  16. {
  17. $node = new EnumNode('foo', null, array('foo', 'bar'));
  18. $this->assertSame('foo', $node->finalize('foo'));
  19. }
  20. /**
  21. * @expectedException \InvalidArgumentException
  22. * @expectedExceptionMessage $values must contain at least one element.
  23. */
  24. public function testConstructionWithNoValues()
  25. {
  26. new EnumNode('foo', null, array());
  27. }
  28. public function testConstructionWithOneValue()
  29. {
  30. $node = new EnumNode('foo', null, array('foo'));
  31. $this->assertSame('foo', $node->finalize('foo'));
  32. }
  33. public function testConstructionWithOneDistinctValue()
  34. {
  35. $node = new EnumNode('foo', null, array('foo', 'foo'));
  36. $this->assertSame('foo', $node->finalize('foo'));
  37. }
  38. /**
  39. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  40. * @expectedExceptionMessage The value "foobar" is not allowed for path "foo". Permissible values: "foo", "bar"
  41. */
  42. public function testFinalizeWithInvalidValue()
  43. {
  44. $node = new EnumNode('foo', null, array('foo', 'bar'));
  45. $node->finalize('foobar');
  46. }
  47. }