Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.5.2 under development

- Bug #788: Fix `skipOnEmpty` default value in `Equal`, `GreaterThan`, `GreaterThanOrEqual`, `LessThan`, `LessThanOrEqual` and `NotEqual` rules from `false` to `null` (@vjik)
Comment thread
vjik marked this conversation as resolved.
Outdated
- Enh #787: Explicitly import classes, functions, and constants in "use" section (@mspirkov)

## 2.5.1 December 12, 2025
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Equal.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct(
?string $message = null,
string $type = CompareType::NUMBER,
bool $strict = false,
bool|callable|null $skipOnEmpty = false,
bool|callable|null $skipOnEmpty = null,
bool $skipOnError = false,
?Closure $when = null,
Comment thread
samdark marked this conversation as resolved.
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/GreaterThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct(
string $incorrectDataSetTypeMessage = self::DEFAULT_INCORRECT_DATA_SET_TYPE_MESSAGE,
?string $message = null,
string $type = CompareType::NUMBER,
bool|callable|null $skipOnEmpty = false,
bool|callable|null $skipOnEmpty = null,
bool $skipOnError = false,
?Closure $when = null,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/GreaterThanOrEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(
string $incorrectDataSetTypeMessage = self::DEFAULT_INCORRECT_DATA_SET_TYPE_MESSAGE,
?string $message = null,
string $type = CompareType::NUMBER,
bool|callable|null $skipOnEmpty = false,
bool|callable|null $skipOnEmpty = null,
bool $skipOnError = false,
?Closure $when = null,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/LessThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct(
string $incorrectDataSetTypeMessage = self::DEFAULT_INCORRECT_DATA_SET_TYPE_MESSAGE,
?string $message = null,
string $type = CompareType::NUMBER,
bool|callable|null $skipOnEmpty = false,
bool|callable|null $skipOnEmpty = null,
bool $skipOnError = false,
?Closure $when = null,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/LessThanOrEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct(
string $incorrectDataSetTypeMessage = self::DEFAULT_INCORRECT_DATA_SET_TYPE_MESSAGE,
?string $message = null,
string $type = CompareType::NUMBER,
bool|callable|null $skipOnEmpty = false,
bool|callable|null $skipOnEmpty = null,
bool $skipOnError = false,
?Closure $when = null,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/NotEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct(
?string $message = null,
string $type = CompareType::NUMBER,
bool $strict = false,
bool|callable|null $skipOnEmpty = false,
bool|callable|null $skipOnEmpty = null,
bool $skipOnError = false,
?Closure $when = null,
) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Rule/EqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Validator;

final class EqualTest extends RuleTestCase
{
Expand Down Expand Up @@ -134,4 +135,11 @@ public function testWhen(): void
$when = static fn(mixed $value): bool => $value !== null;
$this->testWhenInternal(new Equal(1), new Equal(1, when: $when));
}

public function testDefaultSkipOnEmptyCondition(): void
{
$validator = (new Validator())->withDefaultSkipOnEmptyCondition(true);
$result = $validator->validate('', [new Equal(5)]);
$this->assertTrue($result->isValid());
}
}
8 changes: 8 additions & 0 deletions tests/Rule/GreaterThanOrEqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Validator;

final class GreaterThanOrEqualTest extends RuleTestCase
{
Expand Down Expand Up @@ -135,4 +136,11 @@ public function testWhen(): void
$when = static fn(mixed $value): bool => $value !== null;
$this->testWhenInternal(new GreaterThanOrEqual(1), new GreaterThanOrEqual(1, when: $when));
}

public function testDefaultSkipOnEmptyCondition(): void
{
$validator = (new Validator())->withDefaultSkipOnEmptyCondition(true);
$result = $validator->validate('', [new GreaterThanOrEqual(5)]);
$this->assertTrue($result->isValid());
}
}
8 changes: 8 additions & 0 deletions tests/Rule/GreaterThanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Validator;

final class GreaterThanTest extends RuleTestCase
{
Expand Down Expand Up @@ -135,4 +136,11 @@ public function testWhen(): void
$when = static fn(mixed $value): bool => $value !== null;
$this->testWhenInternal(new GreaterThan(1), new GreaterThan(1, when: $when));
}

public function testDefaultSkipOnEmptyCondition(): void
{
$validator = (new Validator())->withDefaultSkipOnEmptyCondition(true);
$result = $validator->validate('', [new GreaterThan(5)]);
$this->assertTrue($result->isValid());
}
}
8 changes: 8 additions & 0 deletions tests/Rule/LessThanOrEqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Validator;

final class LessThanOrEqualTest extends RuleTestCase
{
Expand Down Expand Up @@ -136,4 +137,11 @@ public function testWhen(): void
$when = static fn(mixed $value): bool => $value !== null;
$this->testWhenInternal(new LessThanOrEqual(1), new LessThanOrEqual(1, when: $when));
}

public function testDefaultSkipOnEmptyCondition(): void
{
$validator = (new Validator())->withDefaultSkipOnEmptyCondition(true);
$result = $validator->validate('', [new LessThanOrEqual(5)]);
$this->assertTrue($result->isValid());
}
}
8 changes: 8 additions & 0 deletions tests/Rule/LessThanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Validator;

final class LessThanTest extends RuleTestCase
{
Expand Down Expand Up @@ -135,4 +136,11 @@ public function testWhen(): void
$when = static fn(mixed $value): bool => $value !== null;
$this->testWhenInternal(new LessThan(1), new LessThan(1, when: $when));
}

public function testDefaultSkipOnEmptyCondition(): void
{
$validator = (new Validator())->withDefaultSkipOnEmptyCondition(true);
$result = $validator->validate('', [new LessThan(5)]);
$this->assertTrue($result->isValid());
}
}
8 changes: 8 additions & 0 deletions tests/Rule/NotEqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Tests\Rule\Base\RuleWithOptionsTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
use Yiisoft\Validator\Validator;

final class NotEqualTest extends RuleTestCase
{
Expand Down Expand Up @@ -134,4 +135,11 @@ public function testWhen(): void
$when = static fn(mixed $value): bool => $value !== null;
$this->testWhenInternal(new NotEqual(1), new NotEqual(1, when: $when));
}

public function testDefaultSkipOnEmptyCondition(): void
{
$validator = (new Validator())->withDefaultSkipOnEmptyCondition(true);
$result = $validator->validate('', [new NotEqual(5)]);
$this->assertTrue($result->isValid());
}
}
Loading