Skip to content

Commit 25bba6b

Browse files
Merge branch '5.4' into 6.0
* 5.4: [VarDumper] fix tests on PHP 8.2 [Mime] Add null check for EmailHeaderSame Add approriate description to CollectionToArrayTransformer::reverseTransform docblock [PropertyInfo] CS fixes [VarDumper] fix test on PHP 8.2 [Config] Fix looking for single files in phars with GlobResource Revert "bug #46327 [HttpKernel] Allow ErrorHandler ^5.0 to be used in HttpKernel 4.4 (mpdude)"
2 parents 6357182 + 1ec8c1e commit 25bba6b

File tree

14 files changed

+103
-16
lines changed

14 files changed

+103
-16
lines changed

src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public function transform(mixed $collection): mixed
4646
}
4747

4848
/**
49-
* Transforms choice keys into entities.
50-
*
51-
* @param mixed $array An array of entities
49+
* Transforms an array into a collection.
5250
*/
5351
public function reverseTransform(mixed $array): Collection
5452
{

src/Symfony/Component/Config/Resource/GlobResource.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public function getIterator(): \Traversable
106106
$prefix = str_replace('\\', '/', $this->prefix);
107107
$paths = null;
108108

109-
if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
109+
if ('' === $this->pattern && is_file($prefix)) {
110+
$paths = [$this->prefix];
111+
} elseif (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
110112
if ($this->globBrace || !str_contains($this->pattern, '{')) {
111113
$paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace);
112114
} elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
@@ -167,14 +169,21 @@ function (\SplFileInfo $file, $path) {
167169
throw new \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $this->pattern));
168170
}
169171

172+
if (is_file($prefix = $this->prefix)) {
173+
$prefix = \dirname($prefix);
174+
$pattern = basename($prefix).$this->pattern;
175+
} else {
176+
$pattern = $this->pattern;
177+
}
178+
170179
$finder = new Finder();
171-
$regex = Glob::toRegex($this->pattern);
180+
$regex = Glob::toRegex($pattern);
172181
if ($this->recursive) {
173182
$regex = substr_replace($regex, '(/|$)', -2, 1);
174183
}
175184

176-
$prefixLen = \strlen($this->prefix);
177-
foreach ($finder->followLinks()->sortByName()->in($this->prefix) as $path => $info) {
185+
$prefixLen = \strlen($prefix);
186+
foreach ($finder->followLinks()->sortByName()->in($prefix) as $path => $info) {
178187
$normalizedPath = str_replace('\\', '/', $path);
179188
if (!preg_match($regex, substr($normalizedPath, $prefixLen)) || !$info->isFile()) {
180189
continue;
Binary file not shown.

src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,29 @@ public function testSerializeUnserialize()
208208

209209
$this->assertEquals($p->getValue($resource), $p->getValue($newResource));
210210
}
211+
212+
public function testPhar()
213+
{
214+
$s = \DIRECTORY_SEPARATOR;
215+
$cwd = getcwd();
216+
chdir(\dirname(__DIR__).'/Fixtures');
217+
try {
218+
$resource = new GlobResource('phar://some.phar', '*', true);
219+
$files = array_keys(iterator_to_array($resource));
220+
$this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", "phar://some.phar{$s}schema{$s}project-1.0.xsd"], $files);
221+
222+
$resource = new GlobResource("phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", '', true);
223+
$files = array_keys(iterator_to_array($resource));
224+
$this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php"], $files);
225+
} finally {
226+
chdir($cwd);
227+
}
228+
}
229+
230+
public function testFilePrefix()
231+
{
232+
$resource = new GlobResource(__FILE__, '/**/', true);
233+
$files = array_keys(iterator_to_array($resource));
234+
$this->assertSame([], $files);
235+
}
211236
}

src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ protected function matches($message): bool
5555
*/
5656
protected function failureDescription($message): string
5757
{
58-
return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message));
58+
return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message) ?? 'null');
5959
}
6060

61-
private function getHeaderValue($message): string
61+
private function getHeaderValue($message): ?string
6262
{
63-
$header = $message->getHeaders()->get($this->headerName);
63+
if (null === $header = $message->getHeaders()->get($this->headerName)) {
64+
return null;
65+
}
6466

6567
return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString();
6668
}

src/Symfony/Component/Mime/Tests/EmailTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Mime\Tests;
1313

14+
use PHPUnit\Framework\ExpectationFailedException;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Mime\Address;
1617
use Symfony\Component\Mime\Email;
@@ -19,6 +20,7 @@
1920
use Symfony\Component\Mime\Part\Multipart\MixedPart;
2021
use Symfony\Component\Mime\Part\Multipart\RelatedPart;
2122
use Symfony\Component\Mime\Part\TextPart;
23+
use Symfony\Component\Mime\Test\Constraint\EmailHeaderSame;
2224
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
2325
use Symfony\Component\Serializer\Encoder\JsonEncoder;
2426
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
@@ -458,4 +460,14 @@ public function testSymfonySerialize()
458460
$this->assertEquals($expected->getHeaders(), $n->getHeaders());
459461
$this->assertEquals($expected->getBody(), $n->getBody());
460462
}
463+
464+
public function testMissingHeaderDoesNotThrowError()
465+
{
466+
$this->expectException(ExpectationFailedException::class);
467+
$this->expectExceptionMessage('Failed asserting that the Email has header "foo" with value "bar" (value is null).');
468+
469+
$e = new Email();
470+
$emailHeaderSame = new EmailHeaderSame('foo', 'bar');
471+
$emailHeaderSame->evaluate($e);
472+
}
461473
}

src/Symfony/Component/PropertyInfo/Tests/Fixtures/ConstructorDummy.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
413

514
/**

src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
4-
53
/*
64
* This file is part of the Symfony package.
75
*

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Extractor/DummyNamespace.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace A {
413
class Property {
514

src/Symfony/Component/PropertyInfo/Tests/Fixtures/NoProperties.php

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
4-
53
/*
64
* This file is part of the Symfony package.
75
*

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
413

514
class Php80Dummy

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
413

514
class Php81Dummy

src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
413

514
class PseudoTypeDummy

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testReflectionCaster()
3939
+name: "ReflectionClass"
4040
%Aimplements: array:%d [
4141
%A]
42-
constants: array:3 [
42+
constants: array:%d [
4343
0 => ReflectionClassConstant {
4444
+name: "IS_IMPLICIT_ABSTRACT"
4545
+class: "ReflectionClass"
@@ -58,7 +58,7 @@ public function testReflectionCaster()
5858
modifiers: "public"
5959
value: %d
6060
}
61-
]
61+
%A]
6262
properties: array:%d [
6363
"name" => ReflectionProperty {
6464
%A +name: "name"

0 commit comments

Comments
 (0)