Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/src/Melody/Validation/Constraints/EmailTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marcelo Santos  >  Melody Validation  >  tests/src/Melody/Validation/Constraints/EmailTest.php  >  Download  
File: tests/src/Melody/Validation/Constraints/EmailTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Melody Validation
Validate values according to many types of rules
Author: By
Last change:
Date: 1 year ago
Size: 1,507 bytes
 

Contents

Class file image Download
<?php

namespace Melody\Validation\Constraints;

use 
Melody\Validation\Validator as v;

class 
EmailTest extends \PHPUnit_Framework_TestCase
{

    
/**
     * @dataProvider providerForValidEmail
     */
    
public function test_valid_email_should_pass($validEmail)
    {
        
$this->assertTrue(v::email()->validate($validEmail));
    }

    
/**
     * @dataProvider providerForInvalidEmail
     */
    
public function test_invalid_emails_should_fail_validation($invalidEmail)
    {
        
$this->assertFalse(v::email()->validate($invalidEmail));
    }

    public function 
providerForValidEmail()
    {
        return array(
            array(
'test@test.com'),
            array(
'mail+mail@gmail.com'),
            array(
'mail.email@e.test.com'),
            array(
'a@a.a')
        );
    }

    public function 
providerForInvalidEmail()
    {
        return array(
            array(
'test@test'),
            array(
'test'),
            array(
'test@тест.рф'),
            array(
'@test.com'),
            array(
'mail@test@test.com'),
            array(
'test.test@'),
            array(
'test.@test.com'),
            array(
'test@.test.com'),
            array(
'test@test..com'),
            array(
'test@test.com.'),
            array(
'.test@test.com')
        );
    }

    public function 
test_not_string_argument_exception()
    {
        
$this->setExpectedException('InvalidArgumentException');
        
$this->assertInstanceOf('InvalidArgumentException'v::email()->validate(null));
    }

}