|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace steevanb\SymfonyOptionsResolver\Tests; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use steevanb\SymfonyOptionsResolver\OptionsResolver; |
| 9 | +use Symfony\Component\OptionsResolver\{ |
| 10 | + Exception\InvalidOptionsException, |
| 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 | +} |
0 commit comments