1212namespace  Symfony \Component \VarDumper \Tests \Caster ;
1313
1414use  PHPUnit \Framework \TestCase ;
15+ use  Symfony \Component \VarDumper \Caster \FFICaster ;
1516use  Symfony \Component \VarDumper \Test \VarDumperTestTrait ;
1617
1718/** 
@@ -23,6 +24,11 @@ class FFICasterTest extends TestCase
2324{
2425    use  VarDumperTestTrait;
2526
27+     /** 
28+      * @see FFICaster::MAX_STRING_LENGTH 
29+      */ 
30+     private  const  MAX_STRING_LENGTH  = 255 ;
31+ 
2632    protected  function  setUp (): void 
2733    {
2834        if  (\in_array (\PHP_SAPI , ['cli ' , 'phpdbg ' ], true ) && 'preload '  === \ini_get ('ffi.enable ' )) {
@@ -172,17 +178,24 @@ public function testCastCuttedPointerToChar()
172178    {
173179        $ actualMessagestr_repeat ('Hello World! ' , 30 )."\0" ;
174180        $ actualLength\strlen ($ actualMessage
175- 
176-         $ expectedMessage'Hello World!Hello World!Hello World!Hello World! ' 
177-             .'Hello World!Hello World!Hello World!Hello World!Hello World!Hel ' 
178-             .'lo World!Hello World!Hello World!Hello World!Hello World!Hello  ' 
179-             .'World!Hello World!Hello World!Hello World!Hello World!Hello Wor ' 
180-             .'ld!Hello World!Hel ' ;
181+         $ expectedMessagesubstr ($ actualMessage0 , self ::MAX_STRING_LENGTH );
181182
182183        $ stringFFI ::cdef ()->new ('char[ ' .$ actualLength'] ' );
183184        $ pointerFFI ::addr ($ string0 ]);
184185        \FFI ::memcpy ($ pointer$ actualMessage$ actualLength
185186
187+         // the max length is platform-dependent and can be less than 255, 
188+         // so we need to cut the expected message to the maximum length 
189+         // allowed by pages size of the current system 
190+         $ ffiFFI ::cdef (<<<C 
191+             size_t zend_get_page_size(void); 
192+         C );
193+ 
194+         $ pageSize$ ffizend_get_page_size ();
195+         $ start$ fficast ('uintptr_t ' , $ fficast ('char* ' , $ pointercdata ;
196+         $ maxmin (self ::MAX_STRING_LENGTH , ($ start$ pageSize1 )) - $ start
197+         $ expectedMessagesubstr ($ expectedMessage0 , $ max
198+ 
186199        $ this assertDumpEquals (<<<PHP 
187200        FFI\CData<char*> size 8 align 8 { 
188201          cdata: " $ expectedMessage"… 
0 commit comments