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-
175namespace Yiisoft \Validator \Tests \Rule ;
186
197use PHPUnit \Framework \TestCase ;
8+ use RuntimeException ;
209use Yiisoft \Validator \Rule ;
2110use Yiisoft \Validator \Rule \Url ;
2211
@@ -25,11 +14,18 @@ function function_exists($function)
2514 */
2615class UrlTest extends TestCase
2716{
28- public static bool $ idnFunctionException = false ;
17+ public static ? bool $ idnFunctionExists = null ;
2918
3019 protected function setUp (): void
3120 {
32- static ::$ idnFunctionException = false ;
21+ static ::$ idnFunctionExists = null ;
22+ parent ::setUp ();
23+ }
24+
25+ protected function tearDown (): void
26+ {
27+ static ::$ idnFunctionExists = null ;
28+ parent ::tearDown ();
3329 }
3430
3531 public function testValidate (): void
@@ -110,9 +106,9 @@ public function testValidateWithIdnType(): void
110106
111107 public function testEnableIdnException (): void
112108 {
113- static ::$ idnFunctionException = true ;
109+ static ::$ idnFunctionExists = false ;
114110
115- $ this ->expectException (\ RuntimeException::class);
111+ $ this ->expectException (RuntimeException::class);
116112 (new Url ())->enableIDN ();
117113 }
118114
@@ -199,3 +195,14 @@ public function testOptions(Rule $rule, array $expected): void
199195 $ this ->assertEquals ($ expected , $ rule ->getOptions ());
200196 }
201197}
198+
199+ namespace Yiisoft \Validator \Rule ;
200+
201+ use Yiisoft \Validator \Tests \Rule \UrlTest ;
202+
203+ function function_exists ($ function )
204+ {
205+ return $ function === 'idn_to_ascii ' && UrlTest::$ idnFunctionExists !== null
206+ ? UrlTest::$ idnFunctionExists
207+ : \function_exists ($ function );
208+ }
0 commit comments