| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace Test\Michel\Resolver;
- use Michel\Resolver\Option;
- use Michel\Resolver\OptionsResolver;
- use Michel\UniTester\TestCase;
- class OptionsResolverTest extends TestCase
- {
- protected function setUp(): void
- {
- // TODO: Implement setUp() method.
- }
- protected function tearDown(): void
- {
- // TODO: Implement tearDown() method.
- }
- protected function execute(): void
- {
- $this->testResolveOptionsSuccessfully();
- $this->testMissingRequiredOptions();
- $this->testInvalidOptions();
- }
- public function testResolveOptionsSuccessfully()
- {
- $resolver = new OptionsResolver([
- Option::mixed('option1'),
- Option::mixed('option2')->setOptional('default'),
- ]);
- $options = $resolver->resolve([
- 'option1' => 'value1',
- ]);
- $this->assertStrictEquals($options, ['option1' => 'value1', 'option2' => 'default']);
- }
- public function testMissingRequiredOptions()
- {
- $resolver = new OptionsResolver([
- Option::mixed('requiredOption'),
- ]);
- $this->expectException(\InvalidArgumentException::class, function () use ($resolver) {
- $resolver->resolve([]);
- });
- }
- public function testInvalidOptions()
- {
- $resolver = new OptionsResolver([
- Option::mixed('validOption')->validator(static function ($value) {
- return $value > 0;
- }),
- ]);
- $this->expectException(\InvalidArgumentException::class, function () use ($resolver) {
- $resolver->resolve(['validOption' => 0]);
- });
- }
- }
|