Skip to content

Commit 4a2b846

Browse files
Merge branch '5.4' into 6.2
* 5.4: Fix deprecations on PHP 8.3 [WebProfilerBundle] Fix error in case of 'Content-Type' set null in dev environment with no debug [Routing] Use vsprintf instead of sprintf + unpacking
2 parents c2d9407 + 9aaf7f3 commit 4a2b846

File tree

8 files changed

+46
-37
lines changed

8 files changed

+46
-37
lines changed

src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function onKernelResponse(ResponseEvent $event)
121121
if (self::DISABLED === $this->mode
122122
|| !$response->headers->has('X-Debug-Token')
123123
|| $response->isRedirection()
124-
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
124+
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type') ?? '', 'html'))
125125
|| 'html' !== $request->getRequestFormat()
126126
|| false !== stripos($response->headers->get('Content-Disposition', ''), 'attachment;')
127127
) {

src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ public function testCspIsKeptEnabledIfDumperWasNotUsed()
343343
$this->assertEquals("<html><head></head><body>\nWDT\n</body></html>", $response->getContent());
344344
}
345345

346+
public function testNullContentTypeWithNoDebugEnv()
347+
{
348+
$response = new Response('<html><head></head><body></body></html>');
349+
$response->headers->set('Content-Type', null);
350+
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
351+
352+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
353+
354+
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, null);
355+
$listener->onKernelResponse($event);
356+
357+
$this->expectNotToPerformAssertions();
358+
}
359+
346360
protected function getTwigMock($render = 'WDT')
347361
{
348362
$templating = $this->createMock(Environment::class);

src/Symfony/Component/Console/Tests/TerminalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private function resetStatics()
4141
{
4242
foreach (['height', 'width', 'stty'] as $name) {
4343
$property = new \ReflectionProperty(Terminal::class, $name);
44-
$property->setValue(null);
44+
$property->setValue(null, null);
4545
}
4646
}
4747

src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public function testProcess()
3232
(new RegisterAutoconfigureAttributesPass())->process($container);
3333

3434
$argument = new BoundArgument(1, false, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php'));
35-
$values = $argument->getValues();
36-
--$values[1];
37-
$argument->setValues($values);
3835

3936
$expected = (new ChildDefinition(''))
4037
->setLazy(true)

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ private function disableHttpMethodParameterOverride()
18991899
{
19001900
$class = new \ReflectionClass(Request::class);
19011901
$property = $class->getProperty('httpMethodParameterOverride');
1902-
$property->setValue(false);
1902+
$property->setValue(null, false);
19031903
}
19041904

19051905
private function getRequestInstanceForClientIpTests(string $remoteAddr, ?string $httpForwardedFor, ?array $trustedProxies): Request

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function get(): ?array
296296
$now = microtime();
297297
$now = substr($now, 11).substr($now, 2, 3);
298298

299-
$queuedMessageCount = $this->rawCommand('ZCOUNT', 0, $now);
299+
$queuedMessageCount = $this->rawCommand('ZCOUNT', 0, $now) ?? 0;
300300

301301
while ($queuedMessageCount--) {
302302
if (!$message = $this->rawCommand('ZPOPMIN', 1)) {

src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ private function generateCompiledRoutes(): string
136136
foreach ($staticRoutes as $path => $routes) {
137137
$code .= sprintf(" %s => [\n", self::export($path));
138138
foreach ($routes as $route) {
139-
$r = array_map([__CLASS__, 'export'], $route);
140-
$code .= sprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", $r[0], $r[1], $r[2], $r[3], $r[4], $r[5], $r[6]);
139+
$code .= vsprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", array_map([__CLASS__, 'export'], $route));
141140
}
142141
$code .= " ],\n";
143142
}
@@ -149,8 +148,7 @@ private function generateCompiledRoutes(): string
149148
foreach ($dynamicRoutes as $path => $routes) {
150149
$code .= sprintf(" %s => [\n", self::export($path));
151150
foreach ($routes as $route) {
152-
$r = array_map([__CLASS__, 'export'], $route);
153-
$code .= sprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", $r[0], $r[1], $r[2], $r[3], $r[4], $r[5], $r[6]);
151+
$code .= vsprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", array_map([__CLASS__, 'export'], $route));
154152
}
155153
$code .= " ],\n";
156154
}

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testCastAnonymousStruct()
4040
FFI\CData<struct <anonymous>> size 4 align 4 {
4141
uint32_t x: 0
4242
}
43-
PHP, \FFI::new('struct { uint32_t x; }'));
43+
PHP, \FFI::cdef()->new('struct { uint32_t x; }'));
4444
}
4545

4646
public function testCastNamedStruct()
@@ -49,7 +49,7 @@ public function testCastNamedStruct()
4949
FFI\CData<struct Example> size 4 align 4 {
5050
uint32_t x: 0
5151
}
52-
PHP, \FFI::new('struct Example { uint32_t x; }'));
52+
PHP, \FFI::cdef()->new('struct Example { uint32_t x; }'));
5353
}
5454

5555
public function testCastAnonymousUnion()
@@ -59,7 +59,7 @@ public function testCastAnonymousUnion()
5959
uint32_t x: 0
6060
uint32_t y: 0
6161
}
62-
PHP, \FFI::new('union { uint32_t x; uint32_t y; }'));
62+
PHP, \FFI::cdef()->new('union { uint32_t x; uint32_t y; }'));
6363
}
6464

6565
public function testCastNamedUnion()
@@ -69,7 +69,7 @@ public function testCastNamedUnion()
6969
uint32_t x: 0
7070
uint32_t y: 0
7171
}
72-
PHP, \FFI::new('union Example { uint32_t x; uint32_t y; }'));
72+
PHP, \FFI::cdef()->new('union Example { uint32_t x; uint32_t y; }'));
7373
}
7474

7575
public function testCastAnonymousEnum()
@@ -78,7 +78,7 @@ public function testCastAnonymousEnum()
7878
FFI\CData<enum <anonymous>> size 4 align 4 {
7979
cdata: 0
8080
}
81-
PHP, \FFI::new('enum { a, b }'));
81+
PHP, \FFI::cdef()->new('enum { a, b }'));
8282
}
8383

8484
public function testCastNamedEnum()
@@ -87,7 +87,7 @@ public function testCastNamedEnum()
8787
FFI\CData<enum Example> size 4 align 4 {
8888
cdata: 0
8989
}
90-
PHP, \FFI::new('enum Example { a, b }'));
90+
PHP, \FFI::cdef()->new('enum Example { a, b }'));
9191
}
9292

9393
public static function scalarsDataProvider(): array
@@ -118,7 +118,7 @@ public function testCastScalar(string $type, string $value, int $size, int $alig
118118
FFI\CData<$type> size $size align $align {
119119
cdata: $value
120120
}
121-
PHP, \FFI::new($type));
121+
PHP, \FFI::cdef()->new($type));
122122
}
123123

124124
public function testCastVoidFunction()
@@ -129,7 +129,7 @@ public function testCastVoidFunction()
129129
$abi callable(): void {
130130
returnType: FFI\CType<void> size 1 align 1 {}
131131
}
132-
PHP, \FFI::new('void (*)(void)'));
132+
PHP, \FFI::cdef()->new('void (*)(void)'));
133133
}
134134

135135
public function testCastIntFunction()
@@ -140,7 +140,7 @@ public function testCastIntFunction()
140140
$abi callable(): uint64_t {
141141
returnType: FFI\CType<uint64_t> size 8 align 8 {}
142142
}
143-
PHP, \FFI::new('unsigned long long (*)(void)'));
143+
PHP, \FFI::cdef()->new('unsigned long long (*)(void)'));
144144
}
145145

146146
public function testCastFunctionWithArguments()
@@ -151,14 +151,14 @@ public function testCastFunctionWithArguments()
151151
$abi callable(int32_t, char*): void {
152152
returnType: FFI\CType<void> size 1 align 1 {}
153153
}
154-
PHP, \FFI::new('void (*)(int a, const char* b)'));
154+
PHP, \FFI::cdef()->new('void (*)(int a, const char* b)'));
155155
}
156156

157157
public function testCastNonCuttedPointerToChar()
158158
{
159159
$actualMessage = "Hello World!\0";
160160

161-
$string = \FFI::new('char[100]');
161+
$string = \FFI::cdef()->new('char[100]');
162162
$pointer = \FFI::addr($string[0]);
163163
\FFI::memcpy($pointer, $actualMessage, \strlen($actualMessage));
164164

@@ -180,7 +180,7 @@ public function testCastCuttedPointerToChar()
180180
.'World!Hello World!Hello World!Hello World!Hello World!Hello Wor'
181181
.'ld!Hello World!Hel';
182182

183-
$string = \FFI::new('char['.$actualLength.']');
183+
$string = \FFI::cdef()->new('char['.$actualLength.']');
184184
$pointer = \FFI::addr($string[0]);
185185
\FFI::memcpy($pointer, $actualMessage, $actualLength);
186186

@@ -207,13 +207,13 @@ public function testCastNonTrailingCharPointer()
207207
$actualMessage = 'Hello World!';
208208
$actualLength = \strlen($actualMessage);
209209

210-
$string = \FFI::new('char['.$actualLength.']');
210+
$string = \FFI::cdef()->new('char['.$actualLength.']');
211211
$pointer = \FFI::addr($string[0]);
212212

213213
\FFI::memcpy($pointer, $actualMessage, $actualLength);
214214

215215
// Remove automatically addition of the trailing "\0" and remove trailing "\0"
216-
$pointer = \FFI::cast('char*', \FFI::cast('void*', $pointer));
216+
$pointer = \FFI::cdef()->cast('char*', \FFI::cast('void*', $pointer));
217217
$pointer[$actualLength] = "\x01";
218218

219219
$this->assertDumpMatchesFormat(<<<PHP
@@ -328,24 +328,24 @@ public function testCastPointerToNonEmptyScalars()
328328
CPP);
329329

330330
// Create values
331-
$int = \FFI::new('int64_t');
331+
$int = \FFI::cdef()->new('int64_t');
332332
$int->cdata = 42;
333-
$float = \FFI::new('float');
333+
$float = \FFI::cdef()->new('float');
334334
$float->cdata = 42.0;
335-
$double = \FFI::new('double');
335+
$double = \FFI::cdef()->new('double');
336336
$double->cdata = 42.2;
337-
$bool = \FFI::new('bool');
337+
$bool = \FFI::cdef()->new('bool');
338338
$bool->cdata = true;
339339

340340
// Fill struct
341341
$struct = $ffi->new('Example');
342-
$struct->a = \FFI::addr(\FFI::cast('int8_t', $int));
343-
$struct->b = \FFI::addr(\FFI::cast('uint8_t', $int));
344-
$struct->c = \FFI::addr(\FFI::cast('int64_t', $int));
345-
$struct->d = \FFI::addr(\FFI::cast('uint64_t', $int));
346-
$struct->e = \FFI::addr(\FFI::cast('float', $float));
347-
$struct->f = \FFI::addr(\FFI::cast('double', $double));
348-
$struct->g = \FFI::addr(\FFI::cast('bool', $bool));
342+
$struct->a = \FFI::addr(\FFI::cdef()->cast('int8_t', $int));
343+
$struct->b = \FFI::addr(\FFI::cdef()->cast('uint8_t', $int));
344+
$struct->c = \FFI::addr(\FFI::cdef()->cast('int64_t', $int));
345+
$struct->d = \FFI::addr(\FFI::cdef()->cast('uint64_t', $int));
346+
$struct->e = \FFI::addr(\FFI::cdef()->cast('float', $float));
347+
$struct->f = \FFI::addr(\FFI::cdef()->cast('double', $double));
348+
$struct->g = \FFI::addr(\FFI::cdef()->cast('bool', $bool));
349349

350350
$this->assertDumpEquals(<<<'OUTPUT'
351351
FFI\CData<struct <anonymous>> size 56 align 8 {
@@ -441,7 +441,7 @@ public function testCastComplexType()
441441
$var->func = (static fn (object $p) => 42);
442442

443443
$abi = \PHP_OS_FAMILY === 'Windows' ? '[cdecl]' : '[fastcall]';
444-
$longSize = \FFI::type('long')->getSize();
444+
$longSize = \FFI::cdef()->type('long')->getSize();
445445
$longType = 8 === $longSize ? 'int64_t' : 'int32_t';
446446
$structSize = 56 + $longSize * 2;
447447

0 commit comments

Comments
 (0)