|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase; |
15 | 15 | use Symfony\Component\Notifier\Exception\InvalidArgumentException; |
| 16 | +use Symfony\Component\Notifier\Exception\MissingRequiredOptionException; |
16 | 17 | use Symfony\Component\Notifier\Transport\Dsn; |
17 | 18 |
|
18 | 19 | final class DsnTest extends TestCase |
@@ -120,4 +121,54 @@ public function testGetOption() |
120 | 121 | $this->assertSame('default', $dsn->getOption('nullable', 'default')); |
121 | 122 | $this->assertSame('default', $dsn->getOption('not_existent_property', 'default')); |
122 | 123 | } |
| 124 | + |
| 125 | + public function testGetRequiredOptionGetsOptionIfSet() |
| 126 | + { |
| 127 | + $options = ['with_value' => 'some value']; |
| 128 | + $dsn = new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', $options, '/channel'); |
| 129 | + |
| 130 | + $this->assertSame('some value', $dsn->getRequiredOption('with_value')); |
| 131 | + } |
| 132 | + |
| 133 | + public function testGetRequiredOptionGetsOptionIfValueIsZero() |
| 134 | + { |
| 135 | + $options = ['timeout' => 0]; |
| 136 | + $dsn = new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', $options, '/channel'); |
| 137 | + |
| 138 | + $this->assertSame(0, $dsn->getRequiredOption('timeout')); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * @dataProvider getRequiredOptionThrowsMissingRequiredOptionExceptionProvider |
| 143 | + */ |
| 144 | + public function testGetRequiredOptionThrowsMissingRequiredOptionException(string $expectedExceptionMessage, array $options, string $option) |
| 145 | + { |
| 146 | + $dsn = new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', $options, '/channel'); |
| 147 | + |
| 148 | + $this->expectException(MissingRequiredOptionException::class); |
| 149 | + $this->expectExceptionMessage($expectedExceptionMessage); |
| 150 | + |
| 151 | + $dsn->getRequiredOption($option); |
| 152 | + } |
| 153 | + |
| 154 | + public function getRequiredOptionThrowsMissingRequiredOptionExceptionProvider(): iterable |
| 155 | + { |
| 156 | + yield [ |
| 157 | + 'The option "foo_bar" is required but missing.', |
| 158 | + ['with_value' => 'some value'], |
| 159 | + 'foo_bar', |
| 160 | + ]; |
| 161 | + |
| 162 | + yield [ |
| 163 | + 'The option "with_empty_string" is required but missing.', |
| 164 | + ['with_empty_string' => ''], |
| 165 | + 'with_empty_string', |
| 166 | + ]; |
| 167 | + |
| 168 | + yield [ |
| 169 | + 'The option "with_null" is required but missing.', |
| 170 | + ['with_null' => null], |
| 171 | + 'with_null', |
| 172 | + ]; |
| 173 | + } |
123 | 174 | } |
0 commit comments