Skip to content

Commit 0a10839

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: rewrite tests to not fail when self/parent are resolved at compile time skip failing Semaphore component tests on GitHub Actions with PHP 8.5 Update GetSetMethodNormalizer.php [FrameworkBundle] Disable the keys normalization of the CSRF form field attributes [Stopwatch] Fix StopWatchEvent never throws InvalidArgumentException
2 parents c715827 + a9f661e commit 0a10839

File tree

11 files changed

+147
-26
lines changed

11 files changed

+147
-26
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
253253
->scalarNode('field_name')->defaultValue('_token')->end()
254254
->arrayNode('field_attr')
255255
->performNoDeepMerging()
256+
->normalizeKeys(false)
256257
->scalarPrototype()->end()
257258
->defaultValue(['data-controller' => 'csrf-protection'])
258259
->end()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,22 @@ public function testSerializerJsonDetailedErrorMessagesNotSetByDefaultWithDebugD
706706
$this->assertSame([], $config['serializer']['default_context'] ?? []);
707707
}
708708

709+
public function testFormCsrfProtectionFieldAttrDoNotNormalizeKeys()
710+
{
711+
$processor = new Processor();
712+
$config = $processor->processConfiguration(new Configuration(false), [
713+
[
714+
'form' => [
715+
'csrf_protection' => [
716+
'field_attr' => ['data-example-attr' => 'value'],
717+
],
718+
],
719+
],
720+
]);
721+
722+
$this->assertSame(['data-example-attr' => 'value'], $config['form']['csrf_protection']['field_attr'] ?? []);
723+
}
724+
709725
protected static function getBundleDefaultConfig()
710726
{
711727
return [

src/Symfony/Component/Semaphore/Tests/Store/RelayStoreTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ protected function setUp(): void
2525

2626
public static function setUpBeforeClass(): void
2727
{
28+
if (\PHP_VERSION_ID <= 80500 && isset($_SERVER['GITHUB_ACTIONS'])) {
29+
self::markTestSkipped('Test segfaults on PHP 8.5');
30+
}
31+
2832
try {
2933
new Relay(...explode(':', getenv('REDIS_HOST')));
3034
} catch (\Relay\Exception $e) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private function isSetMethod(\ReflectionMethod $method): bool
100100
return !$method->isStatic()
101101
&& !$method->getAttributes(Ignore::class)
102102
&& 0 < $method->getNumberOfParameters()
103+
&& 3 < \strlen($method->name)
103104
&& str_starts_with($method->name, 'set')
104105
&& !ctype_lower($method->name[3])
105106
;

src/Symfony/Component/Stopwatch/StopwatchEvent.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class StopwatchEvent
3838
* @param string|null $category The event category or null to use the default
3939
* @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision
4040
* @param string|null $name The event name or null to define the name as default
41-
*
42-
* @throws \InvalidArgumentException When the raw time is not valid
4341
*/
4442
public function __construct(
4543
float $origin,
@@ -219,8 +217,6 @@ protected function getNow(): float
219217

220218
/**
221219
* Formats a time.
222-
*
223-
* @throws \InvalidArgumentException When the raw time is not valid
224220
*/
225221
private function formatTime(float $time): float
226222
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
13+
14+
class ReflectionExtractableDummyUsingTrait
15+
{
16+
use ReflectionExtractableTrait;
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
13+
14+
trait ReflectionExtractableTrait
15+
{
16+
public self $self;
17+
18+
public function getSelf(): self
19+
{
20+
return $this;
21+
}
22+
23+
public function setSelf(self $self): void
24+
{
25+
$this->self = $self;
26+
}
27+
}

src/Symfony/Component/TypeInfo/Tests/TypeResolver/ReflectionParameterTypeResolverTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
1616
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableDummy;
17+
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableDummyUsingTrait;
18+
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableTrait;
1719
use Symfony\Component\TypeInfo\Type;
1820
use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory;
1921
use Symfony\Component\TypeInfo\TypeResolver\ReflectionParameterTypeResolver;
@@ -71,15 +73,29 @@ public function testResolveOptionalParameter()
7173
$this->assertEquals(Type::nullable(Type::int()), $this->resolver->resolve($reflectionParameter));
7274
}
7375

74-
public function testCreateTypeContextOrUseProvided()
76+
public function testResolveSelfFromClassWithoutContext()
7577
{
7678
$reflectionClass = new \ReflectionClass(ReflectionExtractableDummy::class);
7779
$reflectionParameter = $reflectionClass->getMethod('setSelf')->getParameters()[0];
7880

7981
$this->assertEquals(Type::object(ReflectionExtractableDummy::class), $this->resolver->resolve($reflectionParameter));
82+
}
83+
84+
public function testResolveSelfFromTraitWithoutContext()
85+
{
86+
$reflectionClass = new \ReflectionClass(ReflectionExtractableTrait::class);
87+
$reflectionParameter = $reflectionClass->getMethod('setSelf')->getParameters()[0];
88+
89+
$this->assertEquals(Type::object(ReflectionExtractableTrait::class), $this->resolver->resolve($reflectionParameter));
90+
}
91+
92+
public function testResolveSelfFromTraitWithClassContext()
93+
{
94+
$reflectionClass = new \ReflectionClass(ReflectionExtractableTrait::class);
95+
$reflectionParameter = $reflectionClass->getMethod('setSelf')->getParameters()[0];
8096

81-
$typeContext = (new TypeContextFactory())->createFromClassName(self::class);
97+
$typeContext = (new TypeContextFactory())->createFromClassName(ReflectionExtractableDummyUsingTrait::class);
8298

83-
$this->assertEquals(Type::object(self::class), $this->resolver->resolve($reflectionParameter, $typeContext));
99+
$this->assertEquals(Type::object(ReflectionExtractableDummyUsingTrait::class), $this->resolver->resolve($reflectionParameter, $typeContext));
84100
}
85101
}

src/Symfony/Component/TypeInfo/Tests/TypeResolver/ReflectionPropertyTypeResolverTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
1616
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableDummy;
17+
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableDummyUsingTrait;
18+
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableTrait;
1719
use Symfony\Component\TypeInfo\Type;
1820
use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory;
1921
use Symfony\Component\TypeInfo\TypeResolver\ReflectionPropertyTypeResolver;
@@ -52,15 +54,29 @@ public function testResolve()
5254
$this->assertEquals(Type::int(), $this->resolver->resolve($reflectionProperty));
5355
}
5456

55-
public function testCreateTypeContextOrUseProvided()
57+
public function testResolveSelfFromClassWithoutContext()
5658
{
5759
$reflectionClass = new \ReflectionClass(ReflectionExtractableDummy::class);
5860
$reflectionProperty = $reflectionClass->getProperty('self');
5961

6062
$this->assertEquals(Type::object(ReflectionExtractableDummy::class), $this->resolver->resolve($reflectionProperty));
63+
}
64+
65+
public function testResolveSelfFromTraitWithoutContext()
66+
{
67+
$reflectionClass = new \ReflectionClass(ReflectionExtractableTrait::class);
68+
$reflectionProperty = $reflectionClass->getProperty('self');
69+
70+
$this->assertEquals(Type::object(ReflectionExtractableTrait::class), $this->resolver->resolve($reflectionProperty));
71+
}
72+
73+
public function testResolveSelfFromTraitWithClassContext()
74+
{
75+
$reflectionClass = new \ReflectionClass(ReflectionExtractableTrait::class);
76+
$reflectionProperty = $reflectionClass->getProperty('self');
6177

62-
$typeContext = (new TypeContextFactory())->createFromClassName(self::class);
78+
$typeContext = (new TypeContextFactory())->createFromClassName(ReflectionExtractableDummyUsingTrait::class);
6379

64-
$this->assertEquals(Type::object(self::class), $this->resolver->resolve($reflectionProperty, $typeContext));
80+
$this->assertEquals(Type::object(ReflectionExtractableDummyUsingTrait::class), $this->resolver->resolve($reflectionProperty, $typeContext));
6581
}
6682
}

src/Symfony/Component/TypeInfo/Tests/TypeResolver/ReflectionReturnTypeResolverTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
1616
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableDummy;
17+
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableDummyUsingTrait;
18+
use Symfony\Component\TypeInfo\Tests\Fixtures\ReflectionExtractableTrait;
1719
use Symfony\Component\TypeInfo\Type;
1820
use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory;
1921
use Symfony\Component\TypeInfo\TypeResolver\ReflectionReturnTypeResolver;
@@ -62,15 +64,29 @@ public function testResolve()
6264
$this->assertEquals(Type::int(), $this->resolver->resolve($reflectionFunction));
6365
}
6466

65-
public function testCreateTypeContextOrUseProvided()
67+
public function testResolveSelfFromClassWithoutContext()
6668
{
6769
$reflectionClass = new \ReflectionClass(ReflectionExtractableDummy::class);
6870
$reflectionFunction = $reflectionClass->getMethod('getSelf');
6971

7072
$this->assertEquals(Type::object(ReflectionExtractableDummy::class), $this->resolver->resolve($reflectionFunction));
73+
}
74+
75+
public function testResolveSelfFromTraitWithoutContext()
76+
{
77+
$reflectionClass = new \ReflectionClass(ReflectionExtractableTrait::class);
78+
$reflectionFunction = $reflectionClass->getMethod('getSelf');
79+
80+
$this->assertEquals(Type::object(ReflectionExtractableTrait::class), $this->resolver->resolve($reflectionFunction));
81+
}
82+
83+
public function testResolveSelfFromTraitWithClassContext()
84+
{
85+
$reflectionClass = new \ReflectionClass(ReflectionExtractableTrait::class);
86+
$reflectionFunction = $reflectionClass->getMethod('getSelf');
7187

72-
$typeContext = (new TypeContextFactory())->createFromClassName(self::class);
88+
$typeContext = (new TypeContextFactory())->createFromClassName(ReflectionExtractableDummyUsingTrait::class);
7389

74-
$this->assertEquals(Type::object(self::class), $this->resolver->resolve($reflectionFunction, $typeContext));
90+
$this->assertEquals(Type::object(ReflectionExtractableDummyUsingTrait::class), $this->resolver->resolve($reflectionFunction, $typeContext));
7591
}
7692
}

0 commit comments

Comments
 (0)