-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e3ec40
commit 86c3e64
Showing
10 changed files
with
195 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Tests\Validator\Constraints; | ||
|
||
use App\Entity\User; | ||
use App\Repository\DomainRepository; | ||
use App\Validator\Constraints\EmailDomain; | ||
use App\Validator\Constraints\EmailDomainValidator; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; | ||
|
||
class EmailDomainValidatorTest extends ConstraintValidatorTestCase | ||
{ | ||
protected function createValidator(): EmailDomainValidator | ||
{ | ||
$repository = $this->createMock(DomainRepository::class); | ||
$repository->expects($this->any()) | ||
->method('findOneBy') | ||
->will($this->returnValue(null)); | ||
|
||
$manager = $this->createMock(EntityManagerInterface::class); | ||
$manager->expects($this->any()) | ||
->method('getRepository') | ||
->will($this->returnValue($repository)); | ||
|
||
return new EmailDomainValidator($manager); | ||
} | ||
|
||
public function testNullIsValid(): void | ||
{ | ||
$this->validator->validate(null, new EmailDomain()); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function testEmptyStringIsValid(): void | ||
{ | ||
$this->validator->validate('', new EmailDomain()); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function testDomainNotFound(): void | ||
{ | ||
$user = new User(); | ||
$user->setEmail('user@example.com'); | ||
$this->validator->validate($user, new EmailDomain()); | ||
|
||
$this->buildViolation('form.missing-domain') | ||
->assertRaised(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Validator/Constraints/PasswordPolicyValidatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Tests\Validator\Constraints; | ||
|
||
use App\Handler\PasswordStrengthHandler; | ||
use App\Validator\Constraints\PasswordPolicy; | ||
use App\Validator\PasswordPolicyValidator; | ||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; | ||
|
||
class PasswordPolicyValidatorTest extends ConstraintValidatorTestCase | ||
{ | ||
protected function createValidator(): PasswordPolicyValidator | ||
{ | ||
$passwordStrengthHandler = new PasswordStrengthHandler(); | ||
return new PasswordPolicyValidator($passwordStrengthHandler); | ||
} | ||
|
||
public function testNullIsValid(): void | ||
{ | ||
$this->validator->validate(null, new PasswordPolicy()); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function testEmptyStringIsValid(): void | ||
{ | ||
$this->validator->validate('', new PasswordPolicy()); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function testValidPassword(): void | ||
{ | ||
$this->validator->validate('Password123!', new PasswordPolicy()); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function testInvalidPassword(): void | ||
{ | ||
$this->validator->validate('password', new PasswordPolicy()); | ||
|
||
$this->buildViolation('form.weak_password') | ||
->assertRaised(); | ||
} | ||
} |
Oops, something went wrong.