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