Skip to content

Commit 3fb90e2

Browse files
committed
[DependencyInjection] Support PHP 8.2 true type
Add test for `null` type
1 parent 3336571 commit 3fb90e2

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
308308
if (false === $value) {
309309
return;
310310
}
311+
} elseif ('true' === $type) {
312+
if (true === $value) {
313+
return;
314+
}
311315
} elseif ($reflectionType->isBuiltin()) {
312316
$checkFunction = sprintf('is_%s', $type);
313317
if ($checkFunction($value)) {

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
3333
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\IntersectionConstructor;
3434
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
35+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructorPHP82;
3536
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo;
3637
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\WaldoFoo;
3738
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Wobble;
@@ -868,6 +869,26 @@ public function testUnionTypePassesWithFalse()
868869
$this->addToAssertionCount(1);
869870
}
870871

872+
/**
873+
* @requires PHP 8.2
874+
*/
875+
public function testUnionTypePassesWithTrue()
876+
{
877+
$container = new ContainerBuilder();
878+
879+
$container->register('unionTrue', UnionConstructorPHP82::class)
880+
->setFactory([UnionConstructorPHP82::class, 'createTrue'])
881+
->setArguments([true]);
882+
883+
$container->register('unionNull', UnionConstructorPHP82::class)
884+
->setFactory([UnionConstructorPHP82::class, 'createNull'])
885+
->setArguments([null]);
886+
887+
(new CheckTypeDeclarationsPass(true))->process($container);
888+
889+
$this->addToAssertionCount(1);
890+
}
891+
871892
/**
872893
* @requires PHP 8
873894
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
4+
5+
class UnionConstructorPHP82
6+
{
7+
public static function createTrue(array|true $arg): static
8+
{
9+
return new static(0);
10+
}
11+
12+
public static function createNull(null $arg): static
13+
{
14+
return new static(0);
15+
}
16+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy