77use function Flow \Types \DSL \{type_from_array , type_html };
88use Flow \Types \Exception \{CastingException , InvalidTypeException };
99use Flow \Types \Value \HTMLDocument ;
10- use PHPUnit \Framework \Attributes \DataProvider ;
10+ use PHPUnit \Framework \Attributes \{ DataProvider , RequiresPhp } ;
1111use PHPUnit \Framework \TestCase ;
1212
1313final class HTMLTypeTest extends TestCase
@@ -60,7 +60,7 @@ public static function assert_data_provider() : \Generator
6060 ];
6161 }
6262
63- public static function cast_data_provider () : \Generator
63+ public static function cast_data_provider_php82 () : \Generator
6464 {
6565 yield 'string to HTML ' => [
6666 'value ' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html> ' ,
@@ -86,6 +86,29 @@ public static function cast_data_provider() : \Generator
8686 ];
8787 }
8888
89+ public static function cast_data_provider_php84 () : \Generator
90+ {
91+ yield 'string to HTML ' => [
92+ 'value ' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html> ' ,
93+ 'expected ' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html> ' ,
94+ 'exceptionClass ' => null ,
95+ ];
96+
97+ yield 'incomplete string to HTML ' => [
98+ 'value ' => '<div><span>1</span></div> ' ,
99+ 'expected ' => <<<'HTML'
100+ <div><span>1</span></div>
101+ HTML,
102+ 'exceptionClass ' => null ,
103+ ];
104+
105+ yield 'object to HTML ' => [
106+ 'value ' => new \stdClass (),
107+ 'expected ' => null ,
108+ 'exceptionClass ' => CastingException::class,
109+ ];
110+ }
111+
89112 public static function is_valid_data_provider () : \Generator
90113 {
91114 yield 'valid HTMLDocument ' => [
@@ -120,8 +143,22 @@ public function test_assert(mixed $value, ?string $exceptionClass = null) : void
120143 }
121144 }
122145
123- #[DataProvider('cast_data_provider ' )]
124- public function test_cast (mixed $ value , mixed $ expected , ?string $ exceptionClass ) : void
146+ #[RequiresPhp('< 8.4 ' )]
147+ #[DataProvider('cast_data_provider_php82 ' )]
148+ public function test_cast_php82 (mixed $ value , mixed $ expected , ?string $ exceptionClass ) : void
149+ {
150+ if ($ exceptionClass !== null ) {
151+ $ this ->expectException ($ exceptionClass );
152+ type_html ()->cast ($ value );
153+ } else {
154+ $ result = type_html ()->cast ($ value );
155+ self ::assertSame ($ expected , $ result ->toString ());
156+ }
157+ }
158+
159+ #[RequiresPhp('>= 8.4 ' )]
160+ #[DataProvider('cast_data_provider_php84 ' )]
161+ public function test_cast_php84 (mixed $ value , mixed $ expected , ?string $ exceptionClass ) : void
125162 {
126163 if ($ exceptionClass !== null ) {
127164 $ this ->expectException ($ exceptionClass );
0 commit comments