whatwedo/validator-test

A fluid Validation tester

v0.2.0 2024-03-25 16:48 UTC

This package is auto-updated.

Last update: 2024-11-25 18:06:13 UTC


README

Fluid Validator Tester, inspired by zenstruck/browser.

Usage

class AppUserValidatorTest extends KernelTestCase
{
    use ValidationTestTrait;


    public function testAppUserRegisterGroup(): void
    {
        $appUser = new AppUser();

        $this->getValidator()

            ->setGroups(['register'])

            ->validate($appUser)
            ->assertCount(4)

            ->assertNotNullTrue('firstname')
            ->validate($appUser->setFirstname('mauri'))
            ->assertNotNullFalse('firstname')

            ->assertCountViolation(4, NotNull::IS_NULL_ERROR);

            ->assertHasViolation(NotNull::IS_NULL_ERROR)
            ->assertHasNoViolation(NotBlank::IS_BLANK_ERROR)

            ->validate($appUser->setEmail('mauri')
            ->assertViolationTrue(Email::INVALID_FORMAT_ERROR, 'email')
            ->validate($appUser->setEmail('mauri@whatwedo.ch'))
            ->assertViolationFalse(Email::INVALID_FORMAT_ERROR, 'email')

           ;
    }

use

        $this->getValidator()
            ->setGroups(['register'])
            ->validate($appUser)
            ->use(function (ConstraintViolationListInterface $constraintViolationList) {
                /*..*/
            })
        ;