| @@ 11-51 (lines=41) @@ | ||
| 8 | use steevanb\SymfonyOptionsResolver\OptionsResolver; |
|
| 9 | use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; |
|
| 10 | ||
| 11 | final class OptionsResolverConfigureOptionTest extends TestCase |
|
| 12 | { |
|
| 13 | public function testValid(): void |
|
| 14 | { |
|
| 15 | $this |
|
| 16 | ->createOptionsResolver() |
|
| 17 | ->resolve(['foo' => 'bar']); |
|
| 18 | ||
| 19 | static::addToAssertionCount(1); |
|
| 20 | } |
|
| 21 | ||
| 22 | public function testInvalidType(): void |
|
| 23 | { |
|
| 24 | $optionsResolver = $this->createOptionsResolver(); |
|
| 25 | ||
| 26 | static::expectException(InvalidOptionsException::class); |
|
| 27 | $optionsResolver->resolve(['foo' => 1]); |
|
| 28 | } |
|
| 29 | ||
| 30 | public function testInvalidAllowedValue(): void |
|
| 31 | { |
|
| 32 | $optionsResolver = $this->createOptionsResolver(); |
|
| 33 | ||
| 34 | static::expectException(InvalidOptionsException::class); |
|
| 35 | $optionsResolver->resolve(['foo' => 'baz']); |
|
| 36 | } |
|
| 37 | ||
| 38 | public function testDefaultValue(): void |
|
| 39 | { |
|
| 40 | $optionsResolver = $this->createOptionsResolver('bar'); |
|
| 41 | $optionsResolver->resolve([]); |
|
| 42 | ||
| 43 | static::addToAssertionCount(1); |
|
| 44 | } |
|
| 45 | ||
| 46 | private function createOptionsResolver(string $defaultValue = null): OptionsResolver |
|
| 47 | { |
|
| 48 | return (new OptionsResolver()) |
|
| 49 | ->configureOption('foo', ['string'], ['bar'], $defaultValue); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||
| @@ 14-54 (lines=41) @@ | ||
| 11 | Exception\MissingOptionsException |
|
| 12 | }; |
|
| 13 | ||
| 14 | final class OptionsResolverConfigureRequiredOptionTest extends TestCase |
|
| 15 | { |
|
| 16 | public function testValid(): void |
|
| 17 | { |
|
| 18 | $this |
|
| 19 | ->createOptionsResolver() |
|
| 20 | ->resolve(['foo' => 'bar']); |
|
| 21 | ||
| 22 | static::addToAssertionCount(1); |
|
| 23 | } |
|
| 24 | ||
| 25 | public function testInvalidType(): void |
|
| 26 | { |
|
| 27 | $optionsResolver = $this->createOptionsResolver(); |
|
| 28 | ||
| 29 | static::expectException(InvalidOptionsException::class); |
|
| 30 | $optionsResolver->resolve(['foo' => 1]); |
|
| 31 | } |
|
| 32 | ||
| 33 | public function testInvalidAllowedValue(): void |
|
| 34 | { |
|
| 35 | $optionsResolver = $this->createOptionsResolver(); |
|
| 36 | ||
| 37 | static::expectException(InvalidOptionsException::class); |
|
| 38 | $optionsResolver->resolve(['foo' => 'baz']); |
|
| 39 | } |
|
| 40 | ||
| 41 | public function testRequiredOption(): void |
|
| 42 | { |
|
| 43 | $optionsResolver = $this->createOptionsResolver(); |
|
| 44 | ||
| 45 | static::expectException(MissingOptionsException::class); |
|
| 46 | $optionsResolver->resolve([]); |
|
| 47 | } |
|
| 48 | ||
| 49 | private function createOptionsResolver(): OptionsResolver |
|
| 50 | { |
|
| 51 | return (new OptionsResolver()) |
|
| 52 | ->configureRequiredOption('foo', ['string'], ['bar']); |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||