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.
81 lines
2.7 KiB
PHP
81 lines
2.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Henrique Moody <henriquemoody@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\Stubs\WithAttributes;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
#[Group(' rule')]
|
|
#[CoversClass(Attributes::class)]
|
|
final class AttributesTest extends TestCase
|
|
{
|
|
#[Test]
|
|
#[DataProvider('providerForNonObjectTypes')]
|
|
public function shouldNotEvaluateNonObjects(mixed $input): void
|
|
{
|
|
self::assertInvalidInput(new Attributes(), $input);
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForObjectTypesWithoutAttributes')]
|
|
public function shouldEvaluateObjectsWithoutPhpAttributes(object $input): void
|
|
{
|
|
self::assertValidInput(new Attributes(), $input);
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForObjectsWithValidPropertyValues')]
|
|
public function shouldNotEvaluateObjectsWithValidPropertyValues(object $input): void
|
|
{
|
|
self::assertValidInput(new Attributes(), $input);
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForObjectsWithInvalidPropertyValues')]
|
|
public function shouldNotEvaluateObjectsWithInvalidPropertyValues(object $input): void
|
|
{
|
|
self::assertInvalidInput(new Attributes(), $input);
|
|
}
|
|
|
|
/** @return array<string, array{object}> */
|
|
public static function providerForObjectsWithValidPropertyValues(): array
|
|
{
|
|
return [
|
|
'All' => [
|
|
new WithAttributes(
|
|
'John Doe',
|
|
'2020-06-23',
|
|
'john.doe@gmail.com',
|
|
'+31206241111',
|
|
'Amstel 1 1011 PN AMSTERDAM Noord-Holland',
|
|
),
|
|
],
|
|
'Only required' => [new WithAttributes('Jane Doe', '2017-11-30', 'janedoe@yahoo.com')],
|
|
];
|
|
}
|
|
|
|
/** @return array<array{object}> */
|
|
public static function providerForObjectsWithInvalidPropertyValues(): array
|
|
{
|
|
return [
|
|
[new WithAttributes('Jane Doe', '2017-11-30')],
|
|
[new WithAttributes('', 'not a date', 'not an email', 'not a phone number')],
|
|
[new WithAttributes('', '1912-06-23', 'john.doe@gmail.com', '+1234567890')],
|
|
[new WithAttributes('John Doe', '1912-06-23', 'not an email', '+1234567890')],
|
|
[new WithAttributes('John Doe', 'not a date', 'john.doe@gmail.com', '+1234567890')],
|
|
[new WithAttributes('John Doe', '1912-06-23', 'john.doe@gmail.com', 'not a phone number')],
|
|
];
|
|
}
|
|
}
|