Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8c5cf0

Browse filesBrowse files
minor #57555 [VarDumper] Fix FFICaster test to be platform-adaptable (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [VarDumper] Fix `FFICaster` test to be platform-adaptable | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Depending on where you run the test, the max length varies (e.g. 255 on my computer, 127 in the CI) Commits ------- d7678f2 [VarDumper] Fix `FFICaster` test to be platform-adaptable
2 parents 1c3c944 + d7678f2 commit f8c5cf0
Copy full SHA for f8c5cf0

File tree

1 file changed

+19
-6
lines changed
Filter options

1 file changed

+19
-6
lines changed

‎src/Symfony/Component/VarDumper/Tests/Caster/FFICasterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/FFICasterTest.php
+19-6Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarDumper\Caster\FFICaster;
1516
use 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
$actualMessage = str_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+
$expectedMessage = substr($actualMessage, 0, self::MAX_STRING_LENGTH);
181182

182183
$string = \FFI::cdef()->new('char['.$actualLength.']');
183184
$pointer = \FFI::addr($string[0]);
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+
$ffi = \FFI::cdef(<<<C
191+
size_t zend_get_page_size(void);
192+
C);
193+
194+
$pageSize = $ffi->zend_get_page_size();
195+
$start = $ffi->cast('uintptr_t', $ffi->cast('char*', $pointer))->cdata;
196+
$max = min(self::MAX_STRING_LENGTH, ($start | ($pageSize - 1)) - $start);
197+
$expectedMessage = substr($expectedMessage, 0, $max);
198+
186199
$this->assertDumpEquals(<<<PHP
187200
FFI\CData<char*> size 8 align 8 {
188201
cdata: "$expectedMessage"…

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.