mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
Refactor `AbstractSearcher` class and its children. Also most of the unnecessary logic that was on `AbstractSearcher` was put back into `In` class. This commit also updates all "SubdivisionCode" rules. The script used to create the classes can be found on: https://gist.github.com/henriquemoody/ec404f994a87b18c7771
89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Respect\Validation\Test\DataProvider\UndefinedProvider;
|
|
|
|
/**
|
|
* @group core
|
|
*
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
final class AbstractSearcherTest extends TestCase
|
|
{
|
|
use UndefinedProvider;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function shouldValidateFromDataSource(): void
|
|
{
|
|
$input = 'bar';
|
|
|
|
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
|
$rule
|
|
->expects($this->once())
|
|
->method('getDataSource')
|
|
->willReturn(['foo', $input, 'baz']);
|
|
|
|
self::assertTrue($rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function shouldNotFindWhenNotIdentical(): void
|
|
{
|
|
$input = 2.0;
|
|
|
|
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
|
$rule
|
|
->expects($this->once())
|
|
->method('getDataSource')
|
|
->willReturn([1, (int) $input, 3]);
|
|
|
|
self::assertFalse($rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @dataProvider providerForUndefined
|
|
*/
|
|
public function shouldValidateWhenValueIsUndefinedAndDataSourceIsEmpty($input): void
|
|
{
|
|
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
|
$rule
|
|
->expects($this->once())
|
|
->method('getDataSource')
|
|
->willReturn([]);
|
|
|
|
self::assertTrue($rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @dataProvider providerForNotUndefined
|
|
*/
|
|
public function shouldNotValidateWhenValueIsNotUndefinedAndDataSourceNotEmpty($input): void
|
|
{
|
|
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
|
$rule
|
|
->expects($this->once())
|
|
->method('getDataSource')
|
|
->willReturn([]);
|
|
|
|
self::assertFalse($rule->validate($input));
|
|
}
|
|
}
|