Skip to content

Commit 71a40f4

Browse files
Merge branch '7.3' into 7.4
* 7.3: run PhpUnitBridge tests with PHPUnit 11.5 Replace backtick operator, deprecated in PHP 8.5, with shell_exec() [DependencyInjection] Add test case to ensure XML parse exception message includes filename and position [Serializer] Fix normalizing objects with accessors having the same name as a property [SecurityBundle] Prevent accessing the tracked token storage when collecting data
2 parents 7b4a6b0 + 27ef10f commit 71a40f4

File tree

9 files changed

+81
-22
lines changed

9 files changed

+81
-22
lines changed

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationGroupTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
1313

14+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationGroup;
1617

18+
#[RequiresPhpunit('<10')]
1719
final class DeprecationGroupTest extends TestCase
1820
{
1921
public function testItGroupsByMessage()

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationNoticeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
1313

14+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationNotice;
1617

18+
#[RequiresPhpunit('<10')]
1719
final class DeprecationNoticeTest extends TestCase
1820
{
1921
public function testItGroupsByCaller()

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
1313

1414
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
1718
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
1819
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7;
1920

21+
#[RequiresPhpunit('<10')]
2022
class DeprecationTest extends TestCase
2123
{
2224
private static $vendorDir;

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
}
191191

192192
$info = [];
193-
foreach (explode("\n", `$COMPOSER info --no-ansi -a -n phpunit/phpunit "$PHPUNIT_VERSION.*"`) as $line) {
193+
foreach (explode("\n", shell_exec("$COMPOSER info --no-ansi -a -n phpunit/phpunit \"$PHPUNIT_VERSION.*\"")) as $line) {
194194
$line = rtrim($line);
195195

196196
if (!$info && preg_match('/^versions +: /', $line)) {

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
101101
}
102102

103103
$logoutUrl = null;
104-
try {
105-
$logoutUrl = $this->logoutUrlGenerator?->getLogoutPath();
106-
} catch (\Exception) {
107-
// fail silently when the logout URL cannot be generated
104+
if ($this->logoutUrlGenerator && method_exists($token, 'getFirewallName')) {
105+
try {
106+
$logoutUrl = $this->logoutUrlGenerator->getLogoutPath($token->getFirewallName());
107+
} catch (\Exception) {
108+
// fail silently when the logout URL cannot be generated
109+
}
108110
}
109111

110112
$this->data = [
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="invalid_service" class="App\Foo">
5+
<bogusTag />
6+
</service>
7+
</services>
8+
</container>

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,4 +1371,20 @@ public function testLoadServicesWithEnvironment()
13711371

13721372
self::assertInstanceOf(RemoteCallerSocket::class, $container->get(RemoteCaller::class));
13731373
}
1374+
1375+
public function testXmlParseExceptionIncludesFilenameAndPosition()
1376+
{
1377+
$container = new ContainerBuilder();
1378+
$loader = new XmlFileLoader(
1379+
$container,
1380+
new FileLocator(__DIR__.'/../Fixtures/xml')
1381+
);
1382+
1383+
$invalidXMLFileName = 'services31.xml';
1384+
1385+
$this->expectException(InvalidArgumentException::class);
1386+
$this->expectExceptionMessageMatches('/Unable to parse file .*services31\.xml.*bogusTag.*This element is not expected.*line 5, column 0/');
1387+
1388+
$loader->load($invalidXMLFileName);
1389+
}
13741390
}

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,21 @@ protected function extractAttributes(object $object, ?string $format = null, arr
8888
$attributeName = null;
8989

9090
// ctype_lower check to find out if method looks like accessor but actually is not, e.g. hash, cancel
91-
if (3 < \strlen($name) && !ctype_lower($name[3]) && match ($name[0]) {
92-
'g' => str_starts_with($name, 'get'),
93-
'h' => str_starts_with($name, 'has'),
94-
'c' => str_starts_with($name, 'can'),
91+
if (match ($name[0]) {
92+
'g' => str_starts_with($name, 'get') && isset($name[$i = 3]),
93+
'h' => str_starts_with($name, 'has') && isset($name[$i = 3]),
94+
'c' => str_starts_with($name, 'can') && isset($name[$i = 3]),
95+
'i' => str_starts_with($name, 'is') && isset($name[$i = 2]),
9596
default => false,
96-
}) {
97-
// getters, hassers and canners
98-
$attributeName = substr($name, 3);
99-
100-
if (!$reflClass->hasProperty($attributeName)) {
101-
$attributeName = lcfirst($attributeName);
102-
}
103-
} elseif ('is' !== $name && str_starts_with($name, 'is') && !ctype_lower($name[2])) {
104-
// issers
105-
$attributeName = substr($name, 2);
106-
107-
if (!$reflClass->hasProperty($attributeName)) {
108-
$attributeName = lcfirst($attributeName);
97+
} && !ctype_lower($name[$i])) {
98+
if ($reflClass->hasProperty($name)) {
99+
$attributeName = $name;
100+
} else {
101+
$attributeName = substr($name, $i);
102+
103+
if (!$reflClass->hasProperty($attributeName)) {
104+
$attributeName = lcfirst($attributeName);
105+
}
109106
}
110107
}
111108

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,20 @@ public function testNormalizeWithMethodNamesSimilarToAccessors()
980980
123 => 321,
981981
], $normalized);
982982
}
983+
984+
public function testNormalizeObjectWithBooleanPropertyAndIsserMethodWithSameName()
985+
{
986+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
987+
$normalizer = new ObjectNormalizer($classMetadataFactory);
988+
989+
$object = new ObjectWithBooleanPropertyAndIsserWithSameName();
990+
$normalized = $normalizer->normalize($object);
991+
992+
$this->assertSame([
993+
'foo' => 'foo',
994+
'isFoo' => true,
995+
], $normalized);
996+
}
983997
}
984998

985999
class ProxyObjectDummy extends ObjectDummy
@@ -1322,3 +1336,19 @@ public function isolate()
13221336
$this->accessorishCalled = true;
13231337
}
13241338
}
1339+
1340+
class ObjectWithBooleanPropertyAndIsserWithSameName
1341+
{
1342+
private $foo = 'foo';
1343+
private $isFoo = true;
1344+
1345+
public function getFoo()
1346+
{
1347+
return $this->foo;
1348+
}
1349+
1350+
public function isFoo()
1351+
{
1352+
return $this->isFoo;
1353+
}
1354+
}

0 commit comments

Comments
 (0)