You are here

class EmailValidatorTest in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/Tests/Constraints/EmailValidatorTest.php \Symfony\Component\Validator\Tests\Constraints\EmailValidatorTest
  2. 8 vendor/egulias/email-validator/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php \Egulias\Tests\EmailValidator\EmailValidatorTest
Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Tests/Constraints/EmailValidatorTest.php \Symfony\Component\Validator\Tests\Constraints\EmailValidatorTest

Hierarchy

Expanded class hierarchy of EmailValidatorTest

File

vendor/symfony/validator/Tests/Constraints/EmailValidatorTest.php, line 18

Namespace

Symfony\Component\Validator\Tests\Constraints
View source
class EmailValidatorTest extends AbstractConstraintValidatorTest {
  protected function getApiVersion() {
    return Validation::API_VERSION_2_5;
  }
  protected function createValidator() {
    return new EmailValidator(false);
  }
  public function testNullIsValid() {
    $this->validator
      ->validate(null, new Email());
    $this
      ->assertNoViolation();
  }
  public function testEmptyStringIsValid() {
    $this->validator
      ->validate('', new Email());
    $this
      ->assertNoViolation();
  }

  /**
   * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
   */
  public function testExpectsStringCompatibleType() {
    $this->validator
      ->validate(new \stdClass(), new Email());
  }

  /**
   * @dataProvider getValidEmails
   */
  public function testValidEmails($email) {
    $this->validator
      ->validate($email, new Email());
    $this
      ->assertNoViolation();
  }
  public function getValidEmails() {
    return array(
      array(
        'fabien@symfony.com',
      ),
      array(
        'example@example.co.uk',
      ),
      array(
        'fabien_potencier@example.fr',
      ),
    );
  }

  /**
   * @dataProvider getInvalidEmails
   */
  public function testInvalidEmails($email) {
    $constraint = new Email(array(
      'message' => 'myMessage',
    ));
    $this->validator
      ->validate($email, $constraint);
    $this
      ->buildViolation('myMessage')
      ->setParameter('{{ value }}', '"' . $email . '"')
      ->setCode(Email::INVALID_FORMAT_ERROR)
      ->assertRaised();
  }
  public function getInvalidEmails() {
    return array(
      array(
        'example',
      ),
      array(
        'example@',
      ),
      array(
        'example@localhost',
      ),
      array(
        'foo@example.com bar',
      ),
    );
  }
  public function testStrict() {
    $constraint = new Email(array(
      'strict' => true,
    ));
    $this->validator
      ->validate('example@localhost', $constraint);
    $this
      ->assertNoViolation();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractConstraintValidatorTest::$constraint protected property
AbstractConstraintValidatorTest::$context protected property 1
AbstractConstraintValidatorTest::$defaultTimezone protected property
AbstractConstraintValidatorTest::$group protected property
AbstractConstraintValidatorTest::$metadata protected property
AbstractConstraintValidatorTest::$object protected property
AbstractConstraintValidatorTest::$propertyPath protected property
AbstractConstraintValidatorTest::$root protected property
AbstractConstraintValidatorTest::$validator protected property 1
AbstractConstraintValidatorTest::$value protected property
AbstractConstraintValidatorTest::assertNoViolation protected function
AbstractConstraintValidatorTest::assertViolation Deprecated protected function
AbstractConstraintValidatorTest::assertViolations Deprecated protected function
AbstractConstraintValidatorTest::buildViolation protected function
AbstractConstraintValidatorTest::createContext protected function
AbstractConstraintValidatorTest::createViolation Deprecated protected function
AbstractConstraintValidatorTest::expectNoValidate protected function
AbstractConstraintValidatorTest::expectValidateAt protected function
AbstractConstraintValidatorTest::expectValidateValueAt protected function
AbstractConstraintValidatorTest::restoreDefaultTimezone protected function
AbstractConstraintValidatorTest::setDefaultTimezone protected function
AbstractConstraintValidatorTest::setGroup protected function
AbstractConstraintValidatorTest::setObject protected function
AbstractConstraintValidatorTest::setProperty protected function
AbstractConstraintValidatorTest::setPropertyPath protected function
AbstractConstraintValidatorTest::setRoot protected function
AbstractConstraintValidatorTest::setUp protected function 2
AbstractConstraintValidatorTest::setValue protected function
AbstractConstraintValidatorTest::tearDown protected function 1
EmailValidatorTest::createValidator protected function Overrides AbstractConstraintValidatorTest::createValidator
EmailValidatorTest::getApiVersion protected function Overrides AbstractConstraintValidatorTest::getApiVersion
EmailValidatorTest::getInvalidEmails public function
EmailValidatorTest::getValidEmails public function
EmailValidatorTest::testEmptyStringIsValid public function
EmailValidatorTest::testExpectsStringCompatibleType public function @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
EmailValidatorTest::testInvalidEmails public function @dataProvider getInvalidEmails
EmailValidatorTest::testNullIsValid public function
EmailValidatorTest::testStrict public function
EmailValidatorTest::testValidEmails public function @dataProvider getValidEmails