passwordEncoder = static::getContainer()->get('security.encoder_factory'); $this->roleRepository = $this->em->getRepository(Role::class); $this->validator = static::getContainer()->get('validator'); } public function testThatItIsNotPossibleToCreateAnUserWithAWeakPassword(): void { $simplePassword = '11111111'; $user = new User(); $user->setFirstName('First Name'); $user->setLastName('LastName'); $user->setUsername('username'); $user->setEmail('some@email.domain'); $user->setPlainPassword($simplePassword); $user->setPassword($this->passwordEncoder->getEncoder($user)->encodePassword($simplePassword, $user->getSalt())); $user->setRole($this->roleRepository->findAll()[0]); $violations = $this->validator->validate($user); $hasNotWeakConstraintViolation = false; /** @var ConstraintViolation $violation */ foreach ($violations as $violation) { $hasNotWeakConstraintViolation |= $violation->getConstraint() instanceof NotWeak; } Assert::assertGreaterThanOrEqual(1, count($violations)); Assert::assertTrue((bool) $hasNotWeakConstraintViolation); } }