22
33declare (strict_types=1 );
44
5+ namespace Yiisoft \Validator \Rule ;
6+
7+ use Yiisoft \Validator \Tests \Rule \UrlTest ;
8+
9+ function function_exists ($ function )
10+ {
11+ if ($ function === 'idn_to_ascii ' && UrlTest::$ idnFunctionException ) {
12+ return false ;
13+ }
14+ return \function_exists ($ function );
15+ }
16+
517namespace Yiisoft \Validator \Tests \Rule ;
618
719use PHPUnit \Framework \TestCase ;
1325 */
1426class UrlTest extends TestCase
1527{
28+ public static bool $ idnFunctionException = false ;
29+
30+ protected function setUp (): void
31+ {
32+ static ::$ idnFunctionException = false ;
33+ }
34+
1635 public function testValidate (): void
1736 {
1837 $ val = new Url ();
@@ -67,7 +86,7 @@ public function testValidateWithCustomScheme(): void
6786
6887 public function testValidateWithIdn (): void
6988 {
70- if (!function_exists ('idn_to_ascii ' )) {
89+ if (!\ function_exists ('idn_to_ascii ' )) {
7190 $ this ->markTestSkipped ('intl package required ' );
7291 return ;
7392 }
@@ -78,6 +97,14 @@ public function testValidateWithIdn(): void
7897 $ this ->assertTrue ($ val ->validate ('http://xn--zcack7ayc9a.de ' )->isValid ());
7998 }
8099
100+ public function testEnableIdnException (): void
101+ {
102+ static ::$ idnFunctionException = true ;
103+
104+ $ this ->expectException (\RuntimeException::class);
105+ (new Url ())->enableIDN ();
106+ }
107+
81108 public function testValidateLength (): void
82109 {
83110 $ url = 'http:// ' . str_pad ('base ' , 2000 , 'url ' ) . '.de ' ;
@@ -87,7 +114,7 @@ public function testValidateLength(): void
87114
88115 public function testValidateWithIdnWithoutScheme (): void
89116 {
90- if (!function_exists ('idn_to_ascii ' )) {
117+ if (!\ function_exists ('idn_to_ascii ' )) {
91118 $ this ->markTestSkipped ('intl package required ' );
92119 return ;
93120 }
0 commit comments