PHP code example of whatwedo / validator-test

1. Go to this page and download the library: Download whatwedo/validator-test library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

whatwedo / validator-test example snippets


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('[email protected]'))
            ->assertViolationFalse(Email::INVALID_FORMAT_ERROR, 'email')

           ;
    }



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