EnumNodeTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, ['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, []);
  27. }
  28. public function testConstructionWithOneValue()
  29. {
  30. $node = new EnumNode('foo', null, ['foo']);
  31. $this->assertSame('foo', $node->finalize('foo'));
  32. }
  33. public function testConstructionWithOneDistinctValue()
  34. {
  35. $node = new EnumNode('foo', null, ['foo', 'foo']);
  36. $this->assertSame('foo', $node->finalize('foo'));
  37. }
  38. public function testConstructionWithNullName()
  39. {
  40. $node = new EnumNode(null, null, ['foo']);
  41. $this->assertSame('foo', $node->finalize('foo'));
  42. }
  43. /**
  44. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  45. * @expectedExceptionMessage The value "foobar" is not allowed for path "foo". Permissible values: "foo", "bar"
  46. */
  47. public function testFinalizeWithInvalidValue()
  48. {
  49. $node = new EnumNode('foo', null, ['foo', 'bar']);
  50. $node->finalize('foobar');
  51. }
  52. }