mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
This commit introduces REUSE compliance by annotating all files with SPDX information and placing the reused licences in the LICENSES folder. We additionally removed the docheader tool which is made obsolete by this change. The main LICENSE and copyright text of the project is now not under my personal name anymore, and it belongs to "The Respect Project Contributors" instead. This change restores author names to several files, giving the appropriate attribution for contributions.
94 lines
2.7 KiB
PHP
94 lines
2.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-FileContributor: Gabriel Caruso <carusogabriel34@gmail.com>
|
|
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
|
|
* SPDX-FileContributor: Mehmet Tolga Avcioglu <mehmet@activecom.net>
|
|
* SPDX-FileContributor: Nick Lombard <github@jigsoft.co.za>
|
|
* SPDX-FileContributor: Róbert Nagy <vrnagy@gmail.com>
|
|
*/
|
|
|
|
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'],
|
|
];
|
|
}
|
|
}
|