mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 16:22:16 +02:00
Remove unused "AbstractSearcher" class
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
a45a0a26ab
commit
794739917a
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Helpers\CanValidateUndefined;
|
||||
|
||||
use function in_array;
|
||||
use function is_scalar;
|
||||
|
||||
abstract class AbstractSearcher extends AbstractRule
|
||||
{
|
||||
use CanValidateUndefined;
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
abstract protected function getDataSource(mixed $input = null): array;
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
{
|
||||
$dataSource = $this->getDataSource($input);
|
||||
|
||||
if ($this->isUndefined($input) && empty($dataSource)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array((string) $input, $dataSource, true);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Test\Rules;
|
||||
|
||||
use Respect\Validation\Rules\AbstractSearcher;
|
||||
|
||||
use function call_user_func;
|
||||
|
||||
final class SearcherStub extends AbstractSearcher
|
||||
{
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $dataSourceCallable;
|
||||
|
||||
public function __construct(callable $dataSourceCallable)
|
||||
{
|
||||
$this->dataSourceCallable = $dataSourceCallable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed, array<mixed>>
|
||||
*/
|
||||
protected function getDataSource(mixed $input = null): array
|
||||
{
|
||||
return call_user_func($this->dataSourceCallable, $input);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Respect\Validation\Test\DataProvider\UndefinedProvider;
|
||||
use Respect\Validation\Test\Rules\SearcherStub;
|
||||
use Respect\Validation\Test\TestCase;
|
||||
|
||||
#[Group('core')]
|
||||
#[CoversClass(AbstractSearcher::class)]
|
||||
final class AbstractSearcherTest extends TestCase
|
||||
{
|
||||
use UndefinedProvider;
|
||||
|
||||
#[Test]
|
||||
public function shouldValidateFromDataSource(): void
|
||||
{
|
||||
$input = 'BAZ';
|
||||
|
||||
$rule = new SearcherStub(static fn() => ['FOO', $input, 'BAZ']);
|
||||
|
||||
self::assertTrue($rule->validate($input));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function shouldNotFindWhenNotIdentical(): void
|
||||
{
|
||||
$input = 2.0;
|
||||
|
||||
$rule = new SearcherStub(static fn() => [1, (int) $input, 3]);
|
||||
|
||||
self::assertFalse($rule->validate($input));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('providerForUndefined')]
|
||||
public function shouldValidateWhenValueIsUndefinedAndDataSourceIsEmpty(mixed $input): void
|
||||
{
|
||||
$rule = new SearcherStub(static fn() => []);
|
||||
|
||||
self::assertTrue($rule->validate($input));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('providerForNotUndefined')]
|
||||
public function shouldNotValidateWhenValueIsNotUndefinedAndDataSourceNotEmpty(mixed $input): void
|
||||
{
|
||||
$rule = new SearcherStub(static fn() => []);
|
||||
|
||||
self::assertFalse($rule->validate($input));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue