Skip to content

Commit

Permalink
Kill mutant
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Sep 7, 2024
1 parent 513a62a commit 4b32bfe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/DataSet/ObjectDataSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Yiisoft\Validator\Label;
use Yiisoft\Validator\Rule\Callback;
use Yiisoft\Validator\Rule\Equal;
use Yiisoft\Validator\Rule\GreaterThan;
use Yiisoft\Validator\Rule\Length;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
Expand Down Expand Up @@ -136,7 +137,6 @@ public function objectWithRulesProvider(): array
[new ObjectDataSet(new ObjectWithRulesProvider())], // Not a duplicate. Used to test caching.
[$dataSet],
[$dataSet], // Not a duplicate. Used to test caching.
[new ObjectDataSet(new ObjectWithIterablePropertyRules())],
];
}

Expand All @@ -161,6 +161,26 @@ public function testObjectWithRulesProvider(ObjectDataSet $dataSet): void
$this->assertInstanceOf(Equal::class, $rules['age'][2]);
}

public function testObjectWithIterablePropertyRules(): void
{
$dataSet = (new ObjectDataSet(new ObjectWithIterablePropertyRules()));
$rules = $dataSet->getRules();

$this->assertSame(['name' => '', 'age' => 17, 'number' => 42], $dataSet->getData());

$this->assertSame('', $dataSet->getPropertyValue('name'));
$this->assertSame(17, $dataSet->getPropertyValue('age'));
$this->assertSame(42, $dataSet->getPropertyValue('number'));
$this->assertNull($dataSet->getPropertyValue('non-exist'));

$this->assertSame(['age', 'name', 'number'], array_keys($rules));
$this->assertCount(4, $rules['age']);
$this->assertInstanceOf(GreaterThan::class, $rules['age'][0]);
$this->assertInstanceOf(Number::class, $rules['age'][1]);
$this->assertInstanceOf(Required::class, $rules['age'][2]);
$this->assertInstanceOf(Equal::class, $rules['age'][3]);
}

public function objectWithDataSetAndRulesProviderDataProvider(): array
{
$dataSet = new ObjectDataSet(new ObjectWithDataSetAndRulesProvider());
Expand Down
2 changes: 2 additions & 0 deletions tests/Support/Data/ObjectWithIterablePropertyRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayObject;
use Yiisoft\Validator\Rule\Equal;
use Yiisoft\Validator\Rule\GreaterThan;
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\RulesProviderInterface;
Expand All @@ -15,6 +16,7 @@ final class ObjectWithIterablePropertyRules implements RulesProviderInterface
#[Required]
public string $name = '';

#[GreaterThan(5)]
#[Number(min: 21)]
protected int $age = 17;

Expand Down

0 comments on commit 4b32bfe

Please sign in to comment.