Skip to content

Commit

Permalink
Remove RulesProviderInterface from rules (#571)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Rogachev <arogachev90@gmail.com>
  • Loading branch information
vjik and arogachev committed Feb 20, 2023
1 parent 3420c01 commit c89a4d7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/Rule/Composite.php
Expand Up @@ -14,7 +14,6 @@
use Yiisoft\Validator\Rule\Trait\WhenTrait;
use Yiisoft\Validator\Helper\RulesDumper;
use Yiisoft\Validator\RuleInterface;
use Yiisoft\Validator\RulesProviderInterface;
use Yiisoft\Validator\RuleWithOptionsInterface;
use Yiisoft\Validator\SkipOnEmptyInterface;
use Yiisoft\Validator\SkipOnErrorInterface;
Expand Down Expand Up @@ -78,7 +77,6 @@ class Composite implements
SkipOnEmptyInterface,
SkipOnErrorInterface,
WhenInterface,
RulesProviderInterface,
AfterInitAttributeEventInterface
{
use SkipOnEmptyTrait;
Expand Down
2 changes: 0 additions & 2 deletions src/Rule/Each.php
Expand Up @@ -17,7 +17,6 @@
use Yiisoft\Validator\Rule\Trait\WhenTrait;
use Yiisoft\Validator\RuleInterface;
use Yiisoft\Validator\Helper\RulesDumper;
use Yiisoft\Validator\RulesProviderInterface;
use Yiisoft\Validator\RuleWithOptionsInterface;
use Yiisoft\Validator\SkipOnEmptyInterface;
use Yiisoft\Validator\SkipOnErrorInterface;
Expand Down Expand Up @@ -67,7 +66,6 @@ final class Each implements
SkipOnEmptyInterface,
SkipOnErrorInterface,
WhenInterface,
RulesProviderInterface,
PropagateOptionsInterface,
AfterInitAttributeEventInterface
{
Expand Down
2 changes: 0 additions & 2 deletions src/Rule/StopOnError.php
Expand Up @@ -14,7 +14,6 @@
use Yiisoft\Validator\Rule\Trait\WhenTrait;
use Yiisoft\Validator\Helper\RulesDumper;
use Yiisoft\Validator\RuleInterface;
use Yiisoft\Validator\RulesProviderInterface;
use Yiisoft\Validator\RuleWithOptionsInterface;
use Yiisoft\Validator\SkipOnEmptyInterface;
use Yiisoft\Validator\SkipOnErrorInterface;
Expand Down Expand Up @@ -51,7 +50,6 @@ final class StopOnError implements
SkipOnEmptyInterface,
SkipOnErrorInterface,
WhenInterface,
RulesProviderInterface,
AfterInitAttributeEventInterface
{
use SkipOnEmptyTrait;
Expand Down
2 changes: 0 additions & 2 deletions tests/Rule/Base/RuleWithProvidedRulesTrait.php
Expand Up @@ -8,7 +8,6 @@
use Yiisoft\Validator\Rule\Number;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\RuleInterface;
use Yiisoft\Validator\RulesProviderInterface;
use Yiisoft\Validator\RuleWithOptionsInterface;

trait RuleWithProvidedRulesTrait
Expand All @@ -24,7 +23,6 @@ private function testGetOptionsWithNotRuleInternal($ruleClassName): void
new Number(min: 1),
]);
$this->assertInstanceOf(RuleWithOptionsInterface::class, $rule);
$this->assertInstanceOf(RulesProviderInterface::class, $rule);

$this->expectException(InvalidArgumentException::class);

Expand Down
5 changes: 5 additions & 0 deletions tests/Rule/EachTest.php
Expand Up @@ -180,6 +180,11 @@ public function dataValidationFailed(): array
[new Each([new Number(max: 13)], incorrectInputMessage: 'Custom incorrect input message.')],
['' => ['Custom incorrect input message.']],
],
'custom incorrect input message, plain Each rule' => [
1,
new Each([new Number(max: 13)], incorrectInputMessage: 'Custom incorrect input message.'),
['' => ['Custom incorrect input message.']],
],
'custom incorrect input message with parameters' => [
1,
[new Each([new Number(max: 13)], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')],
Expand Down
2 changes: 0 additions & 2 deletions tests/Rule/NestedTest.php
Expand Up @@ -30,7 +30,6 @@
use Yiisoft\Validator\Tests\Rule\Base\DifferentRuleInHandlerTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\RuleTestCase;
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\RuleWithProvidedRulesTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Tests\Support\Data\EachNestedObjects\Foo;
Expand All @@ -49,7 +48,6 @@ final class NestedTest extends RuleTestCase
{
use DifferentRuleInHandlerTestTrait;
use RuleWithOptionsTestTrait;
use RuleWithProvidedRulesTrait;
use SkipOnErrorTestTrait;
use WhenTestTrait;

Expand Down
8 changes: 8 additions & 0 deletions tests/Rule/StopOnErrorTest.php
Expand Up @@ -121,6 +121,14 @@ public function dataValidationFailed(): array
],
['' => ['This value must contain at most 1 character.']],
],
'basic, plain StopOnError rule' => [
'hello',
new StopOnError([
new Length(min: 10),
new Length(max: 1),
]),
['' => ['This value must contain at least 10 characters.']],
],
'combined with other top level rules' => [
'hello',
[
Expand Down

0 comments on commit c89a4d7

Please sign in to comment.