Refactor email validation into provider based test

This commit is contained in:
Dan Hensby 2018-09-25 23:15:18 +01:00
parent dcebf56056
commit 7d15d0af70
No known key found for this signature in database
GPG Key ID: 3906B235643EF10B

View File

@ -58,18 +58,34 @@ class EmailTest extends SapphireTest
$this->assertEquals('foo.txt', $child->getFilename());
}
public function testValidEmailAddress()
/**
* @dataProvider provideValidEmailAddresses
*/
public function testValidEmailAddress($email)
{
$validEmails = array('test@example.com', 'test-123@example.sub.com');
$invalidEmails = array('foo.bar@', '@example.com', 'foo@');
$this->assertTrue(Email::is_valid_address($email));
}
foreach ($validEmails as $email) {
$this->assertTrue(Email::is_valid_address($email));
}
/**
* @dataProvider provideInvalidEmailAddresses
*/
public function testInvalidEmailAddress($email)
{
$this->assertFalse(Email::is_valid_address($email));
}
foreach ($invalidEmails as $email) {
$this->assertFalse(Email::is_valid_address($email));
}
public function provideValidEmailAddresses()
{
return [
['test@example.com', 'test-123@sub.example.com'],
];
}
public function provideInvalidEmailAddresses()
{
return [
['foo.bar@', '@example.com', 'foo@'],
];
}
public function testObfuscate()