2015-10-08 18:54:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-10-08 18:54:42 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-08 18:54:42 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2019-04-23 19:35:37 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2015-10-08 18:54:42 +02:00
|
|
|
|
|
|
|
/**
|
2019-04-23 19:35:37 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\KeyValue
|
2018-11-25 17:56:04 +01:00
|
|
|
*
|
2019-04-23 19:35:37 +02:00
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
2018-11-25 17:56:04 +01:00
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2015-10-08 18:54:42 +02:00
|
|
|
*/
|
2019-04-23 19:35:37 +02:00
|
|
|
final class KeyValueTest extends RuleTestCase
|
2015-10-08 18:54:42 +02:00
|
|
|
{
|
2018-07-23 20:35:14 +02:00
|
|
|
/**
|
2019-04-23 19:35:37 +02:00
|
|
|
* {@inheritdoc}
|
2018-07-23 20:35:14 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2015-10-08 18:54:42 +02:00
|
|
|
{
|
2019-04-23 19:35:37 +02:00
|
|
|
return [
|
|
|
|
'Equal values' => [new KeyValue('foo', 'equals', 'bar'), ['foo' => 42, 'bar' => 42]],
|
|
|
|
'A value contained in an array' => [
|
|
|
|
new KeyValue('password', 'in', 'valid_passwords'),
|
|
|
|
[
|
|
|
|
'password' => 'shuberry',
|
|
|
|
'password_confirmation' => 'shuberry',
|
|
|
|
'valid_passwords' => ['shuberry', 'monty-python'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2015-10-08 18:54:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-23 19:35:37 +02:00
|
|
|
* {@inheritdoc}
|
2015-10-08 18:54:42 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2015-10-08 18:54:42 +02:00
|
|
|
{
|
2019-04-23 19:35:37 +02:00
|
|
|
$keyValue = new KeyValue('foo', 'equals', 'bar');
|
2015-10-08 18:54:42 +02:00
|
|
|
|
2019-04-23 19:35:37 +02:00
|
|
|
return [
|
|
|
|
'Different values' => [$keyValue, ['foo' => 43, 'bar' => 42]],
|
|
|
|
'Comparison key does not exist' => [$keyValue, ['bar' => 42]],
|
|
|
|
'Base key does not exist' => [$keyValue, ['foo' => true]],
|
|
|
|
'Rule is not valid' => [new KeyValue('foo', 'probably_not_a_rule', 'bar'), ['foo' => true, 'bar' => false]],
|
|
|
|
];
|
2015-10-08 18:54:42 +02:00
|
|
|
}
|
|
|
|
}
|