respect-validation/tests/unit/Validators/AttributesTest.php
Henrique Moody 7c681fec66
Fix SPDX headers in all files
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.
2026-02-03 15:23:23 +01:00

82 lines
2.8 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>
*/
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')],
];
}
}