Skip to content

Commit 51aa189

Browse files
Run high-deps tests on PHP 8.4
1 parent 7380dca commit 51aa189

11 files changed

+602
-21
lines changed

Tests/Dumper/PhpDumperTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
use Symfony\Component\DependencyInjection\Tests\Fixtures\WitherStaticReturnType;
6969
use Symfony\Component\DependencyInjection\TypedReference;
7070
use Symfony\Component\ExpressionLanguage\Expression;
71+
use Symfony\Component\VarExporter\Internal\LazyDecoratorTrait;
7172
use Symfony\Component\VarExporter\LazyObjectInterface;
7273

7374
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
@@ -920,7 +921,9 @@ public function testDedupLazyProxy()
920921

921922
$dumper = new PhpDumper($container);
922923

923-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dedup_lazy.php', $dumper->dump());
924+
925+
$legacy = \PHP_VERSION_ID < 80400 || !trait_exists(LazyDecoratorTrait::class) ? 'legacy_' : '';
926+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/'.$legacy.'services_dedup_lazy.php', $dumper->dump());
924927
}
925928

926929
public function testLazyArgumentProvideGenerator()
@@ -1616,7 +1619,8 @@ public function testLazyWither()
16161619
$container->compile();
16171620
$dumper = new PhpDumper($container);
16181621
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_Wither_Lazy']);
1619-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_wither_lazy.php', $dump);
1622+
$legacy = \PHP_VERSION_ID < 80400 || !trait_exists(LazyDecoratorTrait::class) ? 'legacy_' : '';
1623+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/'.$legacy.'services_wither_lazy.php', $dump);
16201624
eval('?>'.$dump);
16211625

16221626
$container = new \Symfony_DI_PhpDumper_Service_Wither_Lazy();
@@ -1641,7 +1645,8 @@ public function testLazyWitherNonShared()
16411645
$container->compile();
16421646
$dumper = new PhpDumper($container);
16431647
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared']);
1644-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_wither_lazy_non_shared.php', $dump);
1648+
$legacy = \PHP_VERSION_ID < 80400 || !trait_exists(LazyDecoratorTrait::class) ? 'legacy_' : '';
1649+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/'.$legacy.'services_wither_lazy_non_shared.php', $dump);
16451650
eval('?>'.$dump);
16461651

16471652
$container = new \Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared();
@@ -1978,9 +1983,10 @@ public function testLazyAutowireAttribute()
19781983
$container->compile();
19791984
$dumper = new PhpDumper($container);
19801985

1981-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/lazy_autowire_attribute.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute']));
1986+
$legacy = \PHP_VERSION_ID < 80400 || !trait_exists(LazyDecoratorTrait::class) ? 'legacy_' : '';
1987+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/'.$legacy.'lazy_autowire_attribute.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute']));
19821988

1983-
require self::$fixturesPath.'/php/lazy_autowire_attribute.php';
1989+
require self::$fixturesPath.'/php/'.$legacy.'lazy_autowire_attribute.php';
19841990

19851991
$container = new \Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute();
19861992

@@ -2009,7 +2015,8 @@ public function testLazyAutowireAttributeWithIntersection()
20092015

20102016
$dumper = new PhpDumper($container);
20112017

2012-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/lazy_autowire_attribute_with_intersection.php', $dumper->dump());
2018+
$legacy = \PHP_VERSION_ID < 80400 || !trait_exists(LazyDecoratorTrait::class) ? 'legacy_' : '';
2019+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/'.$legacy.'lazy_autowire_attribute_with_intersection.php', $dumper->dump());
20132020
}
20142021

20152022
public function testCallableAdapterConsumer()

Tests/Fixtures/php/lazy_autowire_attribute.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,23 @@ protected static function getFoo2Service($container, $lazyLoad = true)
8787

8888
class FooProxy4048957 extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
8989
{
90-
use \Symfony\Component\VarExporter\LazyProxyTrait;
90+
use \Symfony\Component\VarExporter\Internal\LazyDecoratorTrait;
9191

9292
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
93+
94+
public function cloneFoo(?\stdClass $bar = null): static
95+
{
96+
${0} = $this->lazyObjectState->realInstance;
97+
${1} = ${0}->cloneFoo(...\func_get_args());
98+
99+
return match (true) {
100+
${1} === ${0} => $this,
101+
!${1} instanceof ${0} || !${0} instanceof ${1} => ${1},
102+
null !== $this->lazyObjectState->cloneInstance =& ${1} => clone $this,
103+
};
104+
}
93105
}
94106

95107
// Help opcache.preload discover always-needed symbols
96108
class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
97109
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
98-
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);

Tests/Fixtures/php/lazy_autowire_attribute_with_intersection.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,16 @@ protected static function get_Lazy_Foo_GDmfketService($container, $lazyLoad = tr
8181

8282
class objectProxy8ac8e9a implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface
8383
{
84-
use \Symfony\Component\VarExporter\LazyProxyTrait;
84+
use \Symfony\Component\VarExporter\Internal\LazyDecoratorTrait;
8585

8686
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
8787

8888
public function initializeLazyObject(): \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface&\Symfony\Component\DependencyInjection\Tests\Compiler\IInterface
8989
{
90-
if ($state = $this->lazyObjectState ?? null) {
91-
return $state->realInstance ??= ($state->initializer)();
92-
}
93-
94-
return $this;
90+
return $this->lazyObjectState->realInstance;
9591
}
9692
}
9793

9894
// Help opcache.preload discover always-needed symbols
9995
class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
10096
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
101-
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
4+
use Symfony\Component\DependencyInjection\ContainerInterface;
5+
use Symfony\Component\DependencyInjection\Container;
6+
use Symfony\Component\DependencyInjection\Exception\LogicException;
7+
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11+
12+
/**
13+
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
14+
*/
15+
class Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute extends Container
16+
{
17+
protected $parameters = [];
18+
19+
public function __construct()
20+
{
21+
$this->services = $this->privates = [];
22+
$this->methodMap = [
23+
'bar' => 'getBarService',
24+
'foo' => 'getFooService',
25+
];
26+
27+
$this->aliases = [];
28+
}
29+
30+
public function compile(): void
31+
{
32+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
33+
}
34+
35+
public function isCompiled(): bool
36+
{
37+
return true;
38+
}
39+
40+
public function getRemovedIds(): array
41+
{
42+
return [
43+
'.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true,
44+
'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true,
45+
];
46+
}
47+
48+
protected function createProxy($class, \Closure $factory)
49+
{
50+
return $factory();
51+
}
52+
53+
/**
54+
* Gets the public 'bar' shared autowired service.
55+
*
56+
* @return \Symfony\Component\DependencyInjection\Tests\Dumper\LazyServiceConsumer
57+
*/
58+
protected static function getBarService($container)
59+
{
60+
return $container->services['bar'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\LazyServiceConsumer(($container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] ?? self::getFoo2Service($container)));
61+
}
62+
63+
/**
64+
* Gets the public 'foo' shared service.
65+
*
66+
* @return \Symfony\Component\DependencyInjection\Tests\Compiler\Foo
67+
*/
68+
protected static function getFooService($container)
69+
{
70+
return $container->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo();
71+
}
72+
73+
/**
74+
* Gets the private '.lazy.Symfony\Component\DependencyInjection\Tests\Compiler\Foo' shared service.
75+
*
76+
* @return \Symfony\Component\DependencyInjection\Tests\Compiler\Foo
77+
*/
78+
protected static function getFoo2Service($container, $lazyLoad = true)
79+
{
80+
if (true === $lazyLoad) {
81+
return $container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] = $container->createProxy('FooProxy4048957', static fn () => \FooProxy4048957::createLazyProxy(static fn () => self::getFoo2Service($container, false)));
82+
}
83+
84+
return ($container->services['foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo());
85+
}
86+
}
87+
88+
class FooProxy4048957 extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
89+
{
90+
use \Symfony\Component\VarExporter\LazyProxyTrait;
91+
92+
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
93+
}
94+
95+
// Help opcache.preload discover always-needed symbols
96+
class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
97+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
98+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
4+
use Symfony\Component\DependencyInjection\ContainerInterface;
5+
use Symfony\Component\DependencyInjection\Container;
6+
use Symfony\Component\DependencyInjection\Exception\LogicException;
7+
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11+
12+
/**
13+
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
14+
*/
15+
class ProjectServiceContainer extends Container
16+
{
17+
protected $parameters = [];
18+
19+
public function __construct()
20+
{
21+
$this->services = $this->privates = [];
22+
$this->methodMap = [
23+
'foo' => 'getFooService',
24+
];
25+
26+
$this->aliases = [];
27+
}
28+
29+
public function compile(): void
30+
{
31+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
32+
}
33+
34+
public function isCompiled(): bool
35+
{
36+
return true;
37+
}
38+
39+
public function getRemovedIds(): array
40+
{
41+
return [
42+
'.lazy.foo.gDmfket' => true,
43+
];
44+
}
45+
46+
protected function createProxy($class, \Closure $factory)
47+
{
48+
return $factory();
49+
}
50+
51+
/**
52+
* Gets the public 'foo' shared autowired service.
53+
*
54+
* @return \Symfony\Component\DependencyInjection\Tests\Compiler\AAndIInterfaceConsumer
55+
*/
56+
protected static function getFooService($container)
57+
{
58+
$a = ($container->privates['.lazy.foo.gDmfket'] ?? self::get_Lazy_Foo_GDmfketService($container));
59+
60+
if (isset($container->services['foo'])) {
61+
return $container->services['foo'];
62+
}
63+
64+
return $container->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Compiler\AAndIInterfaceConsumer($a);
65+
}
66+
67+
/**
68+
* Gets the private '.lazy.foo.gDmfket' shared service.
69+
*
70+
* @return \object
71+
*/
72+
protected static function get_Lazy_Foo_GDmfketService($container, $lazyLoad = true)
73+
{
74+
if (true === $lazyLoad) {
75+
return $container->privates['.lazy.foo.gDmfket'] = $container->createProxy('objectProxy8ac8e9a', static fn () => \objectProxy8ac8e9a::createLazyProxy(static fn () => self::get_Lazy_Foo_GDmfketService($container, false)));
76+
}
77+
78+
return ($container->services['foo'] ?? self::getFooService($container));
79+
}
80+
}
81+
82+
class objectProxy8ac8e9a implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface
83+
{
84+
use \Symfony\Component\VarExporter\LazyProxyTrait;
85+
86+
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
87+
88+
public function initializeLazyObject(): \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface&\Symfony\Component\DependencyInjection\Tests\Compiler\IInterface
89+
{
90+
if ($state = $this->lazyObjectState ?? null) {
91+
return $state->realInstance ??= ($state->initializer)();
92+
}
93+
94+
return $this;
95+
}
96+
}
97+
98+
// Help opcache.preload discover always-needed symbols
99+
class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
100+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
101+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);

0 commit comments

Comments
 (0)