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