From 7d15d0af70a6aae6a23dfd7460331c72b45af6fd Mon Sep 17 00:00:00 2001 From: Dan Hensby Date: Tue, 25 Sep 2018 23:15:18 +0100 Subject: [PATCH] Refactor email validation into provider based test --- tests/php/Control/Email/EmailTest.php | 34 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/tests/php/Control/Email/EmailTest.php b/tests/php/Control/Email/EmailTest.php index 05a2bc2e5..c77b79397 100644 --- a/tests/php/Control/Email/EmailTest.php +++ b/tests/php/Control/Email/EmailTest.php @@ -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()