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

57 lines
1.5 KiB
PHP
Raw Normal View History

2015-10-08 18:54:42 +02:00
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
2015-10-08 18:54:42 +02:00
*/
declare(strict_types=1);
2015-10-08 18:54:42 +02:00
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
2015-10-08 18:54:42 +02:00
/**
* @group rule
*
* @covers \Respect\Validation\Rules\KeyValue
*
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
2015-10-08 18:54:42 +02:00
*/
final class KeyValueTest extends RuleTestCase
2015-10-08 18:54:42 +02:00
{
/**
* {@inheritdoc}
*/
public static function providerForValidInput(): array
2015-10-08 18:54:42 +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
}
/**
* {@inheritdoc}
2015-10-08 18:54:42 +02:00
*/
public static function providerForInvalidInput(): array
2015-10-08 18:54:42 +02:00
{
$keyValue = new KeyValue('foo', 'equals', 'bar');
2015-10-08 18:54:42 +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
}
}