|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Config\Definition\EnumNode;
|
16 | 16 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
| 17 | +use Symfony\Component\Config\Tests\Fixtures\BackedTestEnum; |
| 18 | +use Symfony\Component\Config\Tests\Fixtures\BackedTestEnum2; |
17 | 19 | use Symfony\Component\Config\Tests\Fixtures\TestEnum;
|
18 | 20 | use Symfony\Component\Config\Tests\Fixtures\TestEnum2;
|
19 | 21 |
|
@@ -61,6 +63,67 @@ public function testFinalizeWithInvalidValue()
|
61 | 63 | $node->finalize('foobar');
|
62 | 64 | }
|
63 | 65 |
|
| 66 | + public function testFinalizeWithOnlyUnitEnumFqcnDoesntDoAnythingSpecial() |
| 67 | + { |
| 68 | + $node = new EnumNode('foo', null, [TestEnum::class]); |
| 69 | + |
| 70 | + $this->expectException(InvalidConfigurationException::class); |
| 71 | + $this->expectExceptionMessage('The value "foobar" is not allowed for path "foo". Permissible values: "Symfony\\\\Component\\\\Config\\\\Tests\\\\Fixtures\\\\TestEnum"'); |
| 72 | + |
| 73 | + $node->finalize('foobar'); |
| 74 | + } |
| 75 | + |
| 76 | + public function testFinalizeWithEnumFqcn() |
| 77 | + { |
| 78 | + $node = new EnumNode('foo', null, [BackedTestEnum::class]); |
| 79 | + |
| 80 | + $this->assertSame(BackedTestEnum::Foo, $node->finalize(BackedTestEnum::Foo)); |
| 81 | + } |
| 82 | + |
| 83 | + public function testFinalizeAnotherEnumWithEnumFqcn() |
| 84 | + { |
| 85 | + $node = new EnumNode('foo', null, [BackedTestEnum::class]); |
| 86 | + |
| 87 | + $this->expectException(InvalidConfigurationException::class); |
| 88 | + $this->expectExceptionMessage('The value should be part of the "Symfony\Component\Config\Tests\Fixtures\BackedTestEnum" enum, got a value from the "Symfony\Component\Config\Tests\Fixtures\BackedTestEnum2" enum.'); |
| 89 | + |
| 90 | + $node->finalize(BackedTestEnum2::Foo); |
| 91 | + } |
| 92 | + |
| 93 | + public function testFinalizeWithEnumFqcnAndAnotherScalar() |
| 94 | + { |
| 95 | + $node = new EnumNode('foo', null, [BackedTestEnum::class, 'another_string']); |
| 96 | + |
| 97 | + $this->assertSame(BackedTestEnum::class, $node->finalize(BackedTestEnum::class)); |
| 98 | + } |
| 99 | + |
| 100 | + public function testFinalizeWithEnumFqcnWorksWithPlainString() |
| 101 | + { |
| 102 | + $node = new EnumNode('foo', null, [BackedTestEnum::class]); |
| 103 | + |
| 104 | + $this->assertSame(BackedTestEnum::Foo, $node->finalize('foo')); |
| 105 | + } |
| 106 | + |
| 107 | + public function testFinalizeWithEnumFqcnWithWrongCase() |
| 108 | + { |
| 109 | + $node = new EnumNode('foo', null, [BackedTestEnum::class]); |
| 110 | + |
| 111 | + $this->expectException(InvalidConfigurationException::class); |
| 112 | + $this->expectExceptionMessage('The value "qux" is not allowed for path "foo". Permissible values: foo, bar'); |
| 113 | + |
| 114 | + $node->finalize('qux'); |
| 115 | + } |
| 116 | + |
| 117 | + public function testFinalizeWithEnumFqcnWithWrongType() |
| 118 | + { |
| 119 | + $node = new EnumNode('foo', null, [BackedTestEnum::class]); |
| 120 | + |
| 121 | + $this->expectException(InvalidConfigurationException::class); |
| 122 | + $this->expectExceptionMessage('The value should be either an integer, a string or be part of the "Symfony\Component\Config\Tests\Fixtures\BackedTestEnum" enum, got "bool".'); |
| 123 | + |
| 124 | + $node->finalize(true); |
| 125 | + } |
| 126 | + |
64 | 127 | public function testWithPlaceHolderWithValidValue()
|
65 | 128 | {
|
66 | 129 | $node = new EnumNode('cookie_samesite', null, ['lax', 'strict', 'none']);
|
|
0 commit comments