diff --git a/library/Rules/AbstractSearcher.php b/library/Rules/AbstractSearcher.php deleted file mode 100644 index 6c7a349b6..000000000 --- a/library/Rules/AbstractSearcher.php +++ /dev/null @@ -1,40 +0,0 @@ - - * 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); - } -} diff --git a/tests/library/Rules/SearcherStub.php b/tests/library/Rules/SearcherStub.php deleted file mode 100644 index 4cb5c781d..000000000 --- a/tests/library/Rules/SearcherStub.php +++ /dev/null @@ -1,35 +0,0 @@ - - * 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> - */ - protected function getDataSource(mixed $input = null): array - { - return call_user_func($this->dataSourceCallable, $input); - } -} diff --git a/tests/unit/Rules/AbstractSearcherTest.php b/tests/unit/Rules/AbstractSearcherTest.php deleted file mode 100644 index 38ec39a1d..000000000 --- a/tests/unit/Rules/AbstractSearcherTest.php +++ /dev/null @@ -1,63 +0,0 @@ - - * 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)); - } -}