|
13 | 13 | use Yiisoft\Validator\Label; |
14 | 14 | use Yiisoft\Validator\Rule\Callback; |
15 | 15 | use Yiisoft\Validator\Rule\Equal; |
| 16 | +use Yiisoft\Validator\Rule\GreaterThan; |
16 | 17 | use Yiisoft\Validator\Rule\Length; |
| 18 | +use Yiisoft\Validator\Rule\Number; |
17 | 19 | use Yiisoft\Validator\Rule\Required; |
18 | 20 | use Yiisoft\Validator\RuleInterface; |
19 | 21 | use Yiisoft\Validator\Tests\Support\Data\ObjectWithCallbackMethod\ObjectWithCallbackMethod; |
|
22 | 24 | use Yiisoft\Validator\Tests\Support\Data\ObjectWithDataSetAndRulesProvider; |
23 | 25 | use Yiisoft\Validator\Tests\Support\Data\ObjectWithDifferentPropertyVisibility; |
24 | 26 | use Yiisoft\Validator\Tests\Support\Data\ObjectWithDynamicDataSet; |
| 27 | +use Yiisoft\Validator\Tests\Support\Data\ObjectWithIterablePropertyRules; |
25 | 28 | use Yiisoft\Validator\Tests\Support\Data\ObjectWithLabelsProvider; |
26 | 29 | use Yiisoft\Validator\Tests\Support\Data\ObjectWithRulesProvider; |
27 | 30 | use Yiisoft\Validator\Tests\Support\Data\Post; |
@@ -151,10 +154,31 @@ public function testObjectWithRulesProvider(ObjectDataSet $dataSet): void |
151 | 154 | $this->assertSame(42, $dataSet->getPropertyValue('number')); |
152 | 155 | $this->assertNull($dataSet->getPropertyValue('non-exist')); |
153 | 156 |
|
154 | | - $this->assertSame(['age'], array_keys($rules)); |
155 | | - $this->assertCount(2, $rules['age']); |
156 | | - $this->assertInstanceOf(Required::class, $rules['age'][0]); |
157 | | - $this->assertInstanceOf(Equal::class, $rules['age'][1]); |
| 157 | + $this->assertSame(['age', 'name', 'number'], array_keys($rules)); |
| 158 | + $this->assertCount(3, $rules['age']); |
| 159 | + $this->assertInstanceOf(Number::class, $rules['age'][0]); |
| 160 | + $this->assertInstanceOf(Required::class, $rules['age'][1]); |
| 161 | + $this->assertInstanceOf(Equal::class, $rules['age'][2]); |
| 162 | + } |
| 163 | + |
| 164 | + public function testObjectWithIterablePropertyRules(): void |
| 165 | + { |
| 166 | + $dataSet = (new ObjectDataSet(new ObjectWithIterablePropertyRules())); |
| 167 | + $rules = $dataSet->getRules(); |
| 168 | + |
| 169 | + $this->assertSame(['name' => '', 'age' => 17, 'number' => 42], $dataSet->getData()); |
| 170 | + |
| 171 | + $this->assertSame('', $dataSet->getPropertyValue('name')); |
| 172 | + $this->assertSame(17, $dataSet->getPropertyValue('age')); |
| 173 | + $this->assertSame(42, $dataSet->getPropertyValue('number')); |
| 174 | + $this->assertNull($dataSet->getPropertyValue('non-exist')); |
| 175 | + |
| 176 | + $this->assertSame(['age', 'name', 'number'], array_keys($rules)); |
| 177 | + $this->assertCount(4, $rules['age']); |
| 178 | + $this->assertInstanceOf(GreaterThan::class, $rules['age'][0]); |
| 179 | + $this->assertInstanceOf(Number::class, $rules['age'][1]); |
| 180 | + $this->assertInstanceOf(Required::class, $rules['age'][2]); |
| 181 | + $this->assertInstanceOf(Equal::class, $rules['age'][3]); |
158 | 182 | } |
159 | 183 |
|
160 | 184 | public function objectWithDataSetAndRulesProviderDataProvider(): array |
@@ -391,8 +415,11 @@ public function objectWithLabelsProvider(): array |
391 | 415 | #[Required] |
392 | 416 | #[Label('Test label')] |
393 | 417 | public string $property; |
| 418 | + |
| 419 | + #[Label('Test label 2')] |
| 420 | + public string $property2; |
394 | 421 | }), |
395 | | - ['property' => 'Test label'], |
| 422 | + ['property' => 'Test label', 'property2' => 'Test label 2'], |
396 | 423 | ], |
397 | 424 | ]; |
398 | 425 | } |
|
0 commit comments