mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 14:55:44 +01:00
I ran the `bin/console spdx --fix` with different strategies for different files. For most of the core classes, since they've been drastically rebuilt, I've run it with the `git-blame` strategy, for for the `src/Validators`, in which the API changed completely but the logic remains the same, I use the `git-log` strategy.
91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
|
|
* SPDX-FileContributor: Mehmet Tolga Avcioglu <mehmet@activecom.net>
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Validators;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
#[Group('validator')]
|
|
#[CoversClass(Domain::class)]
|
|
final class DomainTest extends TestCase
|
|
{
|
|
#[Test]
|
|
#[DataProvider('providerForDomainWithoutRealTopLevelDomain')]
|
|
public function itShouldValidateDomainsWithoutRealTopLevelDomain(string $input): void
|
|
{
|
|
self::assertValidInput(new Domain(false), $input);
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForDomainWithRealTopLevelDomain')]
|
|
public function itShouldValidateDomainsWithRealTopLevelDomain(string $input): void
|
|
{
|
|
self::assertValidInput(new Domain(), $input);
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForNonStringTypes')]
|
|
public function itShouldInvalidWhenInputIsNotString(mixed $input): void
|
|
{
|
|
self::assertInvalidInput(new Domain(), $input);
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForInvalidDomains')]
|
|
public function itShouldInvalidInvalidDomains(mixed $input): void
|
|
{
|
|
self::assertInvalidInput(new Domain(), $input);
|
|
}
|
|
|
|
/** @return array<array{string}> */
|
|
public static function providerForDomainWithoutRealTopLevelDomain(): array
|
|
{
|
|
return [
|
|
['111111111111domain.local'],
|
|
['111111111111.domain.local'],
|
|
];
|
|
}
|
|
|
|
/** @return array<array{string}> */
|
|
public static function providerForDomainWithRealTopLevelDomain(): array
|
|
{
|
|
return [
|
|
['example.com'],
|
|
['xn--bcher-kva.ch'],
|
|
['mail.xn--bcher-kva.ch'],
|
|
['example-hyphen.com'],
|
|
['example--valid.com'],
|
|
['std--a.com'],
|
|
['r--w.com'],
|
|
];
|
|
}
|
|
|
|
/** @return array<array{string}> */
|
|
public static function providerForInvalidDomains(): array
|
|
{
|
|
return [
|
|
[''],
|
|
['no dots'],
|
|
['2222222domain.local'],
|
|
['-example-invalid.com'],
|
|
['example.invalid.-com'],
|
|
['xn--bcher--kva.ch'],
|
|
['example.invalid-.com'],
|
|
['1.2.3.256'],
|
|
['1.2.3.4'],
|
|
];
|
|
}
|
|
}
|