respect-validation/tests/unit/Rules/AttributeTest.php

89 lines
2.8 KiB
PHP
Raw Normal View History

2010-09-27 23:02:30 +02:00
<?php
2015-06-08 16:47:14 +02:00
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
2010-09-27 23:02:30 +02:00
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use Respect\Validation\Test\Stubs\WithProperties;
use Respect\Validation\Test\Stubs\WithUninitialized;
2017-11-04 11:21:40 +01:00
/**
* @group rule
*
* @covers \Respect\Validation\Rules\AbstractRelated
* @covers \Respect\Validation\Rules\Attribute
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class AttributeTest extends RuleTestCase
2010-09-27 23:02:30 +02:00
{
public const PROPERTY_VALUE = 'foo';
/**
* @var string
*/
private $bar = self::PROPERTY_VALUE;
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
2015-10-18 03:44:47 +02:00
return [
'attribute is present without extra validator' => [new Attribute('public'), new WithProperties()],
'private attribute is present without extra validator' => [
new Attribute('private'),
new WithProperties(),
],
'attribute is present with extra validator' => [
new Attribute('public', new AlwaysValid()),
new WithProperties(),
],
'attribute is present but uninitialized' => [
new Attribute('uninitialized'),
new WithUninitialized(),
],
'non mandatory attribute is not present' => [
new Attribute('nonexistent', null, false),
new WithProperties(),
],
'non mandatory attribute is not present with extra validator' => [
new Attribute('nonexistent', new AlwaysValid(), false),
new WithProperties(),
],
'attribute is present but uninitialized with extra validator' => [
new Attribute('uninitialized', new AlwaysValid()),
new WithUninitialized(),
],
2015-10-18 03:44:47 +02:00
];
}
2015-10-07 05:54:14 +02:00
/**
* {@inheritDoc}
2015-10-07 05:54:14 +02:00
*/
public static function providerForInvalidInput(): array
2015-10-07 05:54:14 +02:00
{
return [
'attribute is absent without extra validator' => [new Attribute('barr'), new WithProperties()],
'private attribute is not valid based on extra validator' => [
new Attribute('private', new AlwaysInvalid()),
new WithProperties(),
],
'value provided is an empty string' => [new Attribute('barr'), ''],
'validator related to attribute does not validate' => [
new Attribute('public', new AlwaysInvalid()),
new WithProperties(),
],
];
}
}