mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
Make clear when Stub should not be executed
Having a named constructor with a name that clarifies that we don't expect to execute the stub will make it easier to read the tests. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
d25557cd72
commit
3a7ac0240d
|
@ -34,6 +34,11 @@ final class Stub extends AbstractRule
|
|||
$this->validations = $validations;
|
||||
}
|
||||
|
||||
public static function daze(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function pass(int $expectedCount): self
|
||||
{
|
||||
return new self(...array_fill(0, $expectedCount, true));
|
||||
|
|
|
@ -99,7 +99,7 @@ final class FactoryTest extends TestCase
|
|||
{
|
||||
$factory = new Factory();
|
||||
$input = 'input';
|
||||
$rule = Stub::pass(0);
|
||||
$rule = Stub::daze();
|
||||
|
||||
self::assertInstanceOf(ValidationException::class, $factory->exception($rule, $input));
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ final class EachTest extends RuleTestCase
|
|||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new Each(Stub::pass(0)), []],
|
||||
[new Each(Stub::daze()), []],
|
||||
[new Each(Stub::pass(5)), [1, 2, 3, 4, 5]],
|
||||
[new Each(Stub::pass(5)), self::createTraversableInput(1, 5)],
|
||||
[new Each(Stub::pass(5)), self::createStdClassInput(1, 5)],
|
||||
|
@ -85,10 +85,10 @@ final class EachTest extends RuleTestCase
|
|||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new Each(Stub::fail(0)), 123],
|
||||
[new Each(Stub::fail(0)), ''],
|
||||
[new Each(Stub::fail(0)), null],
|
||||
[new Each(Stub::fail(0)), false],
|
||||
[new Each(Stub::daze()), 123],
|
||||
[new Each(Stub::daze()), ''],
|
||||
[new Each(Stub::daze()), null],
|
||||
[new Each(Stub::daze()), false],
|
||||
[new Each(Stub::fail(5)), ['', 2, 3, 4, 5]],
|
||||
[new Each(Stub::fail(5)), ['a', 2, 3, 4, 5]],
|
||||
[new Each(Stub::fail(5)), self::createTraversableInput(1, 5)],
|
||||
|
|
|
@ -33,8 +33,8 @@ final class KeySetTest extends TestCase
|
|||
$this->expectExceptionMessage('KeySet rule accepts only Key rules');
|
||||
|
||||
new KeySet(new AllOf(
|
||||
new Key('foo', Stub::pass(0), false),
|
||||
new Key('bar', Stub::pass(0), false),
|
||||
new Key('foo', Stub::daze(), false),
|
||||
new Key('bar', Stub::daze(), false),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ final class KeySetTest extends TestCase
|
|||
$this->expectException(ComponentException::class);
|
||||
$this->expectExceptionMessage('KeySet rule accepts only Key rules');
|
||||
|
||||
new KeySet(new AllOf(Stub::pass(0)));
|
||||
new KeySet(new AllOf(Stub::daze()));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
|
@ -53,7 +53,7 @@ final class KeySetTest extends TestCase
|
|||
$this->expectException(ComponentException::class);
|
||||
$this->expectExceptionMessage('KeySet rule accepts only Key rules');
|
||||
|
||||
new KeySet(Stub::pass(0));
|
||||
new KeySet(Stub::daze());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
|
@ -65,7 +65,7 @@ final class KeySetTest extends TestCase
|
|||
|
||||
$sut = new KeySet(
|
||||
new Key('foo', Stub::pass(1), true),
|
||||
new Key('bar', Stub::pass(0), true),
|
||||
new Key('bar', Stub::daze(), true),
|
||||
);
|
||||
|
||||
self::assertFalse($sut->validate($input));
|
||||
|
@ -80,7 +80,7 @@ final class KeySetTest extends TestCase
|
|||
|
||||
$sut = new KeySet(
|
||||
new Key('foo', Stub::pass(1), true),
|
||||
new Key('bar', Stub::pass(0), false),
|
||||
new Key('bar', Stub::daze(), false),
|
||||
);
|
||||
|
||||
self::assertTrue($sut->validate($input));
|
||||
|
@ -107,8 +107,8 @@ final class KeySetTest extends TestCase
|
|||
public function shouldValidateKeysWhenEmpty(): void
|
||||
{
|
||||
$sut = new KeySet(
|
||||
new Key('foo', Stub::pass(0), true),
|
||||
new Key('bar', Stub::pass(0), true),
|
||||
new Key('foo', Stub::daze(), true),
|
||||
new Key('bar', Stub::daze(), true),
|
||||
);
|
||||
|
||||
self::assertFalse($sut->validate([]));
|
||||
|
|
|
@ -43,7 +43,7 @@ final class NullableTest extends TestCase
|
|||
#[DoesNotPerformAssertions]
|
||||
public function shouldNotAssertRuleWhenInputIsNull(): void
|
||||
{
|
||||
$sut = new Nullable(Stub::pass(0));
|
||||
$sut = new Nullable(Stub::daze());
|
||||
$sut->assert(null);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ final class NullableTest extends TestCase
|
|||
#[DoesNotPerformAssertions]
|
||||
public function shouldNotCheckRuleWhenInputIsNull(): void
|
||||
{
|
||||
$rule = new Nullable(Stub::pass(0));
|
||||
$rule = new Nullable(Stub::daze());
|
||||
$rule->check(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ final class PropertyTest extends RuleTestCase
|
|||
new WithProperties(),
|
||||
],
|
||||
'non mandatory attribute is not present with extra validator' => [
|
||||
new Property('nonexistent', Stub::pass(0), false),
|
||||
new Property('nonexistent', Stub::daze(), false),
|
||||
new WithProperties(),
|
||||
],
|
||||
'attribute is present but uninitialized with extra validator' => [
|
||||
|
@ -58,7 +58,7 @@ final class PropertyTest extends RuleTestCase
|
|||
{
|
||||
return [
|
||||
'attribute is absent without extra validator' => [new Property('barr'), new WithProperties()],
|
||||
'attribute is absent with extra validator' => [new Property('barr', Stub::fail(0)), new WithProperties()],
|
||||
'attribute is absent with extra validator' => [new Property('barr', Stub::daze()), new WithProperties()],
|
||||
'private attribute is not valid based on extra validator' => [
|
||||
new Property('private', Stub::fail(1)),
|
||||
new WithProperties(),
|
||||
|
|
Loading…
Reference in a new issue