From 4aee468dea66ef518da096549bb86fe9d9e89fb7 Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Wed, 27 Apr 2016 16:07:11 +1200 Subject: [PATCH] only fail when at least 5 domains extensions are failing, so it does not fail every time IANA adds a new domain extension... --- .../Integration/EmailValidatorTest.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/PHPUnit/Integration/EmailValidatorTest.php b/tests/PHPUnit/Integration/EmailValidatorTest.php index 2b9e9e82da..75b37e5a60 100644 --- a/tests/PHPUnit/Integration/EmailValidatorTest.php +++ b/tests/PHPUnit/Integration/EmailValidatorTest.php @@ -34,6 +34,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase unset($tlds[$key]); } } + $minimumTlds = 1200; + $this->assertGreaterThan( $minimumTlds, count($tlds), "expected to download at least $minimumTlds domain names"); return $tlds; } @@ -44,8 +46,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase } } - public function test_allCurrentTlds(){ - + public function test_allCurrentTlds() + { $this->skipTestIfIdnNotAvailable(); $tlds = $this->getAllTlds(); @@ -53,19 +55,27 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped("Couldn't get TLD list"); } + $errors = array(); foreach ($tlds as $key => $tld) { if (strpos(mb_strtolower($tld), 'xn--') !== 0) { $tld = mb_strtolower($tld); } - $email = 'test@example.' . idn_to_utf8($tld); - $this->assertTrue( - $this->isValid($email), - "email $email is not valid, but expected to be valid. Add this domain extension to libs/Zend/Validate/Hostname.php" - ); + $domainNameExtension = idn_to_utf8($tld); + $email = 'test@example.' . $domainNameExtension; + + if(!$this->isValid($email)) { + $errors[] = "email $email is not valid, but expected to be valid. Add this domain extension to libs/Zend/Validate/Hostname.php"; + } + } + + // only fail when at least 5 domains are failing the test, so it does not fail every time IANA adds a new domain extension... + if(count($errors) > 5) { + $this->fail( implode(", ", $errors)); } } - public function test_invalidTld(){ + public function test_invalidTld() + { $this->skipTestIfIdnNotAvailable(); $tlds = [ -- GitLab