UserPassword example

namespace Symfony\Component\Security\Core\Tests\Validator\Constraints;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;

class UserPasswordTest extends TestCase
{
    public function testValidatedByStandardValidator()
    {
        $constraint = new UserPassword();

        self::assertSame('security.validator.user_password', $constraint->validatedBy());
    }

    /** * @dataProvider provideServiceValidatedConstraints */
    public function testValidatedByService(UserPassword $constraint)
    {
        self::assertSame('my_service', $constraint->validatedBy());
    }

    
->willReturn(false);

        $this->validator->validate('secret', $constraint);

        $this->buildViolation('myMessage')
            ->setCode(UserPassword::INVALID_PASSWORD_ERROR)
            ->assertRaised();
    }

    public static function provideConstraints(): iterable
    {
        yield 'Doctrine style' => [new UserPassword(['message' => 'myMessage'])];

        yield 'named arguments' => [new UserPassword(message: 'myMessage')];
    }

    /** * @dataProvider emptyPasswordData */
    public function testEmptyPasswordsAreNotValid($password)
    {
        $constraint = new UserPassword([
            'message' => 'myMessage',
        ]);
Home | Imprint | This part of the site doesn't use cookies.