Skip to content

Commit fcb3150

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: fix test fix test [SecurityBundle] Fix failing tests fix tests [DependencyInjection] fix unable to make lazy service from readonly class [Dotenv] Specify envKey while loading variables with the dotenv:dump command [Mailer][Postmark][Webhook] Accept different date formats
2 parents 2443bfe + ac9b684 commit fcb3150

File tree

18 files changed

+69
-19
lines changed

18 files changed

+69
-19
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/CacheWarmer/ExpressionCacheWarmerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public function testWarmUp()
3131
$expressionLang = $this->createMock(ExpressionLanguage::class);
3232
$expressionLang->expects($this->exactly(2))
3333
->method('parse')
34-
->willReturnCallback(function (...$args) use (&$series) {
35-
$expectedArgs = array_shift($series);
36-
$this->assertSame($expectedArgs, $args);
34+
->willReturnCallback(function (Expression|string $expression, array $names) use (&$series) {
35+
[$expectedExpression, $expectedNames] = array_shift($series);
36+
37+
$this->assertSame($expectedExpression, $expression);
38+
$this->assertSame($expectedNames, $names);
3739

3840
return $this->createMock(ParsedExpression::class);
3941
})

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ private function generateProxyClasses(): array
609609
$proxyCode = substr(self::stripComments($proxyCode), 5);
610610
}
611611

612-
$proxyClass = explode(' ', $this->inlineRequires ? substr($proxyCode, \strlen($code)) : $proxyCode, 3)[1];
612+
$proxyClass = $this->inlineRequires ? substr($proxyCode, \strlen($code)) : $proxyCode;
613+
$i = strpos($proxyClass, 'class');
614+
$proxyClass = substr($proxyClass, 6 + $i, strpos($proxyClass, ' ', 7 + $i) - $i - 6);
613615

614616
if ($this->asFiles || $this->namespace) {
615617
$proxyCode .= "\nif (!\\class_exists('$proxyClass', false)) {\n \\class_alias(__NAMESPACE__.'\\\\$proxyClass', '$proxyClass', false);\n}\n";

src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/LazyServiceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getProxyCode(Definition $definition, ?string $id = null): string
105105

106106
if ($asGhostObject) {
107107
try {
108-
return 'class '.$proxyClass.ProxyHelper::generateLazyGhost($class);
108+
return (\PHP_VERSION_ID >= 80200 && $class?->isReadOnly() ? 'readonly ' : '').'class '.$proxyClass.ProxyHelper::generateLazyGhost($class);
109109
} catch (LogicException $e) {
110110
throw new InvalidArgumentException(sprintf('Cannot generate lazy ghost for service "%s".', $id ?? $definition->getClass()), 0, $e);
111111
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\DependencyInjection\Tests\Fixtures;
13+
14+
readonly class ReadOnlyClass
15+
{
16+
public function say(): string
17+
{
18+
return 'hello';
19+
}
20+
}

src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\LazyServiceDumper;
19+
use Symfony\Component\DependencyInjection\Tests\Fixtures\ReadOnlyClass;
1920

2021
class LazyServiceDumperTest extends TestCase
2122
{
@@ -52,6 +53,18 @@ public function testInvalidClass()
5253
$this->expectExceptionMessage('Invalid "proxy" tag for service "stdClass": class "stdClass" doesn\'t implement "Psr\Container\ContainerInterface".');
5354
$dumper->getProxyCode($definition);
5455
}
56+
57+
/**
58+
* @requires PHP 8.3
59+
*/
60+
public function testReadonlyClass()
61+
{
62+
$dumper = new LazyServiceDumper();
63+
$definition = (new Definition(ReadOnlyClass::class))->setLazy(true);
64+
65+
$this->assertTrue($dumper->isProxyCandidate($definition));
66+
$this->assertStringContainsString('readonly class ReadOnlyClassGhost', $dumper->getProxyCode($definition));
67+
}
5568
}
5669

5770
final class TestContainer implements ContainerInterface

src/Symfony/Component/Dotenv/Command/DotenvDumpCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9595

9696
private function loadEnv(string $dotenvPath, string $env, array $config): array
9797
{
98-
$dotenv = new Dotenv();
9998
$envKey = $config['env_var_name'] ?? 'APP_ENV';
10099
$testEnvs = $config['test_envs'] ?? ['test'];
101100

101+
$dotenv = new Dotenv($envKey);
102+
102103
$globalsBackup = [$_SERVER, $_ENV];
103104
unset($_SERVER[$envKey]);
104105
$_ENV = [$envKey => $env];

src/Symfony/Component/Mailer/Bridge/Postmark/RemoteEvent/PostmarkPayloadConverter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ public function convert(array $payload): AbstractMailerEvent
4747
'SpamComplaint' => $payload['BouncedAt'],
4848
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['RecordType'])),
4949
};
50-
if (!$date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', $payloadDate)) {
50+
51+
$date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $payloadDate)
52+
// microseconds, 6 digits
53+
?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $payloadDate)
54+
// microseconds, 7 digits
55+
?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u?P', $payloadDate);
56+
57+
if (!$date) {
5158
throw new ParseException(sprintf('Invalid date "%s".', $payloadDate));
5259
}
5360
$event->setDate($date);

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/bounce.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Details": "Test bounce details",
1717
"Email": "[email protected]",
1818
"From": "[email protected]",
19-
"BouncedAt": "2022-09-02T14:29:19Z",
19+
"BouncedAt": "2022-09-02T14:29:19.1234567Z",
2020
"DumpAvailable": true,
2121
"Inactive": true,
2222
"CanActivate": true,

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/bounce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
$wh->setTags(['Test']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
99
$wh->setReason('The server was unable to deliver your message (ex: unknown user, mailbox not found).');
10-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:19Z'));
10+
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2022-09-02T14:29:19.123456Z'));
1111

1212
return $wh;

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/delivery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
$wh->setTags(['welcome-email']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
99
$wh->setReason('');
10-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T11:49:27Z'));
10+
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T11:49:27Z'));
1111

1212
return $wh;

0 commit comments

Comments
 (0)