whatwedo / validator-test
A fluid Validation tester
Installs: 6 042
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 12
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- symfony/doctrine-bridge: ^5.4|^6.4|^7.0
- symfony/framework-bundle: ^5.4|^6.4|^7.0
- symfony/validator: ^5.4|^6.4|^7.0
- zenstruck/callback: ~1.4
Requires (Dev)
- doctrine/annotations: ^1.0|^2.0
- symfony/phpunit-bridge: ^5.4|^6.4|^7.0
This package is auto-updated.
Last update: 2024-10-25 17:58:53 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) { /*..*/ }) ;