|
17 | 17 | use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry; |
18 | 18 | use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager; |
19 | 19 | use PHPUnit\Framework\Attributes\CoversClass; |
| 20 | +use PHPUnit\Framework\Attributes\DataProvider; |
20 | 21 | use PHPUnit\Framework\TestCase; |
| 22 | +use Symfony\Component\OptionsResolver\Exception\ExceptionInterface as OptionsResolverException; |
21 | 23 | use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; |
| 24 | +use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; |
| 25 | +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; |
22 | 26 | use Symfony\Component\Validator\Constraints\Length; |
23 | 27 | use Symfony\Component\Validator\Constraints\NotBlank; |
24 | 28 |
|
@@ -59,9 +63,7 @@ public function testDefaultUiOptions(): void |
59 | 63 | /** @var mixed $run the PHPDoc type of the option is wrong */ |
60 | 64 | $run = $options['run']; |
61 | 65 | self::assertNull($run); |
62 | | - // The "default" nested option is not asserted: defined with setDefault() and a closure, it is not resolved as |
63 | | - // a nested option with symfony/options-resolver 8 (the closure itself is returned) |
64 | | - self::assertArrayHasKey('default', $options); |
| 66 | + self::assertSame(['input' => null, 'context' => []], $options['default']); |
65 | 67 | } |
66 | 68 |
|
67 | 69 | public function testConfiguredUiOptions(): void |
@@ -100,6 +102,54 @@ public function testConfiguredUiOptions(): void |
100 | 102 | self::assertSame(10, $options['constraints'][1]->max); |
101 | 103 | } |
102 | 104 |
|
| 105 | + public function testDefaultWithoutContext(): void |
| 106 | + { |
| 107 | + $manager = $this->createManager([ |
| 108 | + 'test.process' => $this->rawProcess(['ui' => ['default' => ['input' => 'data.csv']]]), |
| 109 | + ]); |
| 110 | + |
| 111 | + $options = $manager->getUiOptions('test.process'); |
| 112 | + |
| 113 | + self::assertNotNull($options); |
| 114 | + self::assertSame(['input' => 'data.csv', 'context' => []], $options['default']); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @param array<string, mixed> $default |
| 119 | + * @param class-string<OptionsResolverException> $exception |
| 120 | + */ |
| 121 | + #[DataProvider('provideInvalidDefault')] |
| 122 | + public function testInvalidDefault(array $default, string $exception): void |
| 123 | + { |
| 124 | + $manager = $this->createManager(['test.process' => $this->rawProcess(['ui' => ['default' => $default]])]); |
| 125 | + |
| 126 | + $this->expectException($exception); |
| 127 | + $manager->getUiOptions('test.process'); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @return iterable<string, array{array<string, mixed>, class-string<OptionsResolverException>}> |
| 132 | + */ |
| 133 | + public static function provideInvalidDefault(): iterable |
| 134 | + { |
| 135 | + yield 'unknown option' => [['inputs' => 'data.csv'], UndefinedOptionsException::class]; |
| 136 | + yield 'context is not an array' => [['context' => 'foo'], InvalidOptionsException::class]; |
| 137 | + yield 'context item is not an array' => [['context' => ['foo']], InvalidOptionsException::class]; |
| 138 | + yield 'context item without value' => [['context' => [['key' => 'foo']]], MissingOptionsException::class]; |
| 139 | + yield 'context item with an unknown option' => [ |
| 140 | + ['context' => [['key' => 'foo', 'value' => 'bar', 'type' => 'string']]], |
| 141 | + UndefinedOptionsException::class, |
| 142 | + ]; |
| 143 | + } |
| 144 | + |
| 145 | + public function testDefaultIsNotAnArray(): void |
| 146 | + { |
| 147 | + $manager = $this->createManager(['test.process' => $this->rawProcess(['ui' => ['default' => 'data.csv']])]); |
| 148 | + |
| 149 | + $this->expectException(InvalidOptionsException::class); |
| 150 | + $manager->getUiOptions('test.process'); |
| 151 | + } |
| 152 | + |
103 | 153 | public function testInvalidEntrypointType(): void |
104 | 154 | { |
105 | 155 | $manager = $this->createManager(['test.process' => $this->rawProcess(['ui' => ['entrypoint_type' => 'csv']])]); |
|
0 commit comments