Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42ae534

Browse files
Merge branch '6.0' into 6.1
* 6.0: [VarExporter] fix tests on Windows [GHA] Fix psalm job Fix CS [PropertyInfo] strip only leading `\` when unknown docType [RateLimiter] Fix rate serialization for long intervals (monthly and yearly) ignoring exception from sem_get in SemaphoreStore Lock component, preventing of error: identifier removed [Console] Fix compact table style to avoid outputting a leading space fix: stringify from address for ses+api transport [Mailer] Use recipients in sendmail transport [Serializer] Fix nested deserialization_path computation when there is no metadata for the attribute [Asset] Update the error message when assets are not built
2 parents 68fa5a5 + 2ed7d0d commit 42ae534

File tree

23 files changed

+240
-59
lines changed

23 files changed

+240
-59
lines changed

.github/psalm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*
22
!.gitignore
3+
!stubs
4+
!stubs/*

.github/workflows/psalm.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@ jobs:
3939
([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json"
4040
export COMPOSER_ROOT_VERSION=$(grep ' VERSION = ' src/Symfony/Component/HttpKernel/Kernel.php | grep -P -o '[0-9]+\.[0-9]+').x-dev
4141
composer remove --dev --no-update --no-interaction symfony/phpunit-bridge
42-
composer require --no-update psalm/phar phpunit/phpunit:^9.5 php-http/discovery psr/event-dispatcher mongodb/mongodb
43-
44-
echo "::group::composer update"
45-
composer update --no-progress --ansi
46-
git checkout composer.json
47-
echo "::endgroup::"
48-
49-
./vendor/bin/psalm.phar --version
42+
composer require --no-progress --ansi psalm/phar phpunit/phpunit:^9.5 php-http/discovery psr/event-dispatcher mongodb/mongodb
5043
5144
- name: Generate Psalm baseline
5245
run: |
46+
git checkout composer.json
5347
git checkout -m ${{ github.base_ref }}
48+
5449
./vendor/bin/psalm.phar --set-baseline=.github/psalm/psalm.baseline.xml --no-progress
5550
git checkout -m FETCH_HEAD
5651

src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function getManifestPath(string $path): ?string
8181
}
8282
} else {
8383
if (!is_file($this->manifestPath)) {
84-
throw new RuntimeException(sprintf('Asset manifest file "%s" does not exist.', $this->manifestPath));
84+
throw new RuntimeException(sprintf('Asset manifest file "%s" does not exist. Did you forget to build the assets with npm or yarn?', $this->manifestPath));
8585
}
8686

8787
try {

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ private static function initStyles(): array
782782
$compact = new TableStyle();
783783
$compact
784784
->setHorizontalBorderChars('')
785-
->setVerticalBorderChars(' ')
785+
->setVerticalBorderChars('')
786786
->setDefaultCrossingChar('')
787-
->setCellRowContentFormat('%s')
787+
->setCellRowContentFormat('%s ')
788788
;
789789

790790
$styleGuide = new TableStyle();

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ public function renderProvider()
119119
$books,
120120
'compact',
121121
<<<'TABLE'
122-
ISBN Title Author
123-
99921-58-10-7 Divine Comedy Dante Alighieri
124-
9971-5-0210-0 A Tale of Two Cities Charles Dickens
125-
960-425-059-0 The Lord of the Rings J. R. R. Tolkien
126-
80-902734-1-6 And Then There Were None Agatha Christie
122+
ISBN Title Author
123+
99921-58-10-7 Divine Comedy Dante Alighieri
124+
9971-5-0210-0 A Tale of Two Cities Charles Dickens
125+
960-425-059-0 The Lord of the Rings J. R. R. Tolkien
126+
80-902734-1-6 And Then There Were None Agatha Christie
127127

128128
TABLE
129129
],

src/Symfony/Component/Lock/Store/SemaphoreStore.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ private function lock(Key $key, bool $blocking)
6363
}
6464

6565
$keyId = unpack('i', md5($key, true))[1];
66-
$resource = sem_get($keyId);
67-
$acquired = @sem_acquire($resource, !$blocking);
66+
$resource = @sem_get($keyId);
67+
$acquired = $resource && @sem_acquire($resource, !$blocking);
6868

6969
while ($blocking && !$acquired) {
70-
$resource = sem_get($keyId);
71-
$acquired = @sem_acquire($resource);
70+
$resource = @sem_get($keyId);
71+
$acquired = $resource && @sem_acquire($resource);
7272
}
7373

7474
if (!$acquired) {

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testSend()
8383
$this->assertSame('Hello!', $content['Content']['Simple']['Subject']['Data']);
8484
$this->assertSame('"Saif Eddin" <[email protected]>', $content['Destination']['ToAddresses'][0]);
8585
$this->assertSame('=?UTF-8?B?SsOpcsOpbXk=?= <[email protected]>', $content['Destination']['CcAddresses'][0]);
86-
$this->assertSame('"Fabien" <[email protected]>', $content['FromEmailAddress']);
86+
$this->assertSame('=?UTF-8?B?RmFiacOpbg==?= <[email protected]>', $content['FromEmailAddress']);
8787
$this->assertSame('Hello There!', $content['Content']['Simple']['Body']['Text']['Data']);
8888
$this->assertSame('<b>Hello There!</b>', $content['Content']['Simple']['Body']['Html']['Data']);
8989
$this->assertSame(['[email protected]', '[email protected]'], $content['ReplyToAddresses']);
@@ -105,7 +105,7 @@ public function testSend()
105105
$mail->subject('Hello!')
106106
->to(new Address('[email protected]', 'Saif Eddin'))
107107
->cc(new Address('[email protected]', 'Jérémy'))
108-
->from(new Address('[email protected]', 'Fabien'))
108+
->from(new Address('[email protected]', 'Fabién'))
109109
->text('Hello There!')
110110
->html('<b>Hello There!</b>')
111111
->replyTo(new Address('[email protected]'), new Address('[email protected]'))

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function getRequest(SentMessage $message): SendEmailRequest
5454
$envelope = $message->getEnvelope();
5555

5656
$request = [
57-
'FromEmailAddress' => $envelope->getSender()->toString(),
57+
'FromEmailAddress' => $this->stringifyAddress($envelope->getSender()),
5858
'Destination' => [
5959
'ToAddresses' => $this->stringifyAddresses($this->getRecipients($email, $envelope)),
6060
],
@@ -121,15 +121,20 @@ private function getRecipients(Email $email, Envelope $envelope): array
121121
protected function stringifyAddresses(array $addresses): array
122122
{
123123
return array_map(function (Address $a) {
124-
// AWS does not support UTF-8 address
125-
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
126-
return sprintf('=?UTF-8?B?%s?= <%s>',
127-
base64_encode($name),
128-
$a->getEncodedAddress()
129-
);
130-
}
131-
132-
return $a->toString();
124+
return $this->stringifyAddress($a);
133125
}, $addresses);
134126
}
127+
128+
protected function stringifyAddress(Address $a): string
129+
{
130+
// AWS does not support UTF-8 address
131+
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
132+
return sprintf('=?UTF-8?B?%s?= <%s>',
133+
base64_encode($name),
134+
$a->getEncodedAddress()
135+
);
136+
}
137+
138+
return $a->toString();
139+
}
135140
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env php
2+
<?php
3+
$argsPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'sendmail_args';
4+
5+
file_put_contents($argsPath, implode(' ', $argv));

src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,81 @@
1212
namespace Symfony\Component\Mailer\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\DelayedEnvelope;
1516
use Symfony\Component\Mailer\Transport\SendmailTransport;
17+
use Symfony\Component\Mime\Address;
18+
use Symfony\Component\Mime\Email;
1619

1720
class SendmailTransportTest extends TestCase
1821
{
22+
private const FAKE_SENDMAIL = __DIR__.'/Fixtures/fake-sendmail.php -t';
23+
24+
/**
25+
* @var string
26+
*/
27+
private $argsPath;
28+
29+
protected function setUp(): void
30+
{
31+
$this->argsPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'sendmail_args';
32+
}
33+
34+
protected function tearDown(): void
35+
{
36+
if (file_exists($this->argsPath)) {
37+
@unlink($this->argsPath);
38+
}
39+
unset($this->argsPath);
40+
}
41+
1942
public function testToString()
2043
{
2144
$t = new SendmailTransport();
2245
$this->assertEquals('smtp://sendmail', (string) $t);
2346
}
47+
48+
public function testToIsUsedWhenRecipientsAreNotSet()
49+
{
50+
if ('\\' === \DIRECTORY_SEPARATOR) {
51+
$this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams');
52+
}
53+
54+
$mail = new Email();
55+
$mail
56+
57+
58+
->subject('Subject')
59+
->text('Some text')
60+
;
61+
62+
$envelope = new DelayedEnvelope($mail);
63+
64+
$sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL);
65+
$sendmailTransport->send($mail, $envelope);
66+
67+
$this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php [email protected] [email protected]');
68+
}
69+
70+
public function testRecipientsAreUsedWhenSet()
71+
{
72+
if ('\\' === \DIRECTORY_SEPARATOR) {
73+
$this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams');
74+
}
75+
76+
$mail = new Email();
77+
$mail
78+
79+
80+
->subject('Subject')
81+
->text('Some text')
82+
;
83+
84+
$envelope = new DelayedEnvelope($mail);
85+
$envelope->setRecipients([new Address('[email protected]')]);
86+
87+
$sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL);
88+
$sendmailTransport->send($mail, $envelope);
89+
90+
$this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php [email protected] [email protected]');
91+
}
2492
}

src/Symfony/Component/Mailer/Transport/SendmailTransport.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ protected function doSend(SentMessage $message): void
9191
$this->getLogger()->debug(sprintf('Email transport "%s" starting', __CLASS__));
9292

9393
$command = $this->command;
94+
95+
if ($recipients = $message->getEnvelope()->getRecipients()) {
96+
$command = str_replace(' -t', '', $command);
97+
}
98+
9499
if (!str_contains($command, ' -f')) {
95100
$command .= ' -f'.escapeshellarg($message->getEnvelope()->getSender()->getEncodedAddress());
96101
}
@@ -101,6 +106,10 @@ protected function doSend(SentMessage $message): void
101106
$chunks = AbstractStream::replace("\n.", "\n..", $chunks);
102107
}
103108

109+
foreach ($recipients as $recipient) {
110+
$command .= ' '.escapeshellarg($recipient->getEncodedAddress());
111+
}
112+
104113
$this->stream->setCommand($command);
105114
$this->stream->initialize();
106115
foreach ($chunks as $chunk) {

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\DBAL\Exception as DBALException;
1717
use Doctrine\DBAL\Exception\TableNotFoundException;
1818
use Doctrine\DBAL\LockMode;
19-
use Doctrine\DBAL\Platforms\MySqlPlatform;
19+
use Doctrine\DBAL\Platforms\MySQLPlatform;
2020
use Doctrine\DBAL\Query\QueryBuilder;
2121
use Doctrine\DBAL\Result;
2222
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@@ -413,7 +413,7 @@ private function addTableToSchema(Schema $schema): void
413413
->setNotnull(false);
414414
$table->setPrimaryKey(['id']);
415415
// No indices on queue_name and available_at on MySQL to prevent deadlock issues when running multiple consumers.
416-
if (!$this->driverConnection->getDatabasePlatform() instanceof MySqlPlatform) {
416+
if (!$this->driverConnection->getDatabasePlatform() instanceof MySQLPlatform) {
417417
$table->addIndex(['queue_name']);
418418
$table->addIndex(['available_at']);
419419
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
1818
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
1919
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy;
20+
use Symfony\Component\PropertyInfo\Tests\Fixtures\PseudoTypeDummy;
2021
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
2122
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
2223
use Symfony\Component\PropertyInfo\Type;
@@ -389,6 +390,11 @@ public function propertiesParentTypeProvider(): array
389390
];
390391
}
391392

393+
public function testUnknownPseudoType()
394+
{
395+
$this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, 'scalar')], $this->extractor->getTypes(PseudoTypeDummy::class, 'unknownPseudoType'));
396+
}
397+
392398
/**
393399
* @dataProvider constructorTypesProvider
394400
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
4+
5+
class PseudoTypeDummy
6+
{
7+
/**
8+
* @var scalar
9+
*/
10+
public $unknownPseudoType;
11+
}

src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,6 @@ private function getPhpTypeAndClass(string $docType): array
187187
return ['object', $docType];
188188
}
189189

190-
return ['object', substr($docType, 1)]; // substr to strip the namespace's `\`-prefix
190+
return ['object', ltrim($docType, '\\')];
191191
}
192192
}

src/Symfony/Component/RateLimiter/Policy/Rate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ public function calculateNewTokensDuringInterval(float $duration): int
101101

102102
public function __toString(): string
103103
{
104-
return $this->refillTime->format('P%y%m%dDT%HH%iM%sS').'-'.$this->refillAmount;
104+
return $this->refillTime->format('P%yY%mM%dDT%HH%iM%sS').'-'.$this->refillAmount;
105105
}
106106
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\RateLimiter\Tests\Policy;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\RateLimiter\Policy\Rate;
16+
17+
class RateTest extends TestCase
18+
{
19+
/**
20+
* @dataProvider provideRate
21+
*/
22+
public function testFromString(Rate $rate)
23+
{
24+
$this->assertEquals($rate, Rate::fromString((string) $rate));
25+
}
26+
27+
public function provideRate(): iterable
28+
{
29+
yield [new Rate(\DateInterval::createFromDateString('15 seconds'), 10)];
30+
yield [Rate::perSecond(10)];
31+
yield [Rate::perMinute(10)];
32+
yield [Rate::perHour(10)];
33+
yield [Rate::perDay(10)];
34+
yield [Rate::perMonth(10)];
35+
yield [Rate::perYear(10)];
36+
}
37+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ private function getAttributeNormalizationContext(object $object, string $attrib
242242
*/
243243
private function getAttributeDenormalizationContext(string $class, string $attribute, array $context): array
244244
{
245+
$context['deserialization_path'] = ($context['deserialization_path'] ?? false) ? $context['deserialization_path'].'.'.$attribute : $attribute;
246+
245247
if (null === $metadata = $this->getAttributeMetadata($class, $attribute)) {
246248
return $context;
247249
}
248250

249-
$context['deserialization_path'] = ($context['deserialization_path'] ?? false) ? $context['deserialization_path'].'.'.$attribute : $attribute;
250-
251251
return array_merge($context, $metadata->getDenormalizationContextForGroups($this->getGroups($context)));
252252
}
253253

src/Symfony/Component/Serializer/Tests/Fixtures/Php74Full.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ final class Php74Full
2929
public array $collection;
3030
public Php74FullWithConstructor $php74FullWithConstructor;
3131
public DummyMessageInterface $dummyMessage;
32+
/** @var TestFoo[] $nestedArray */
33+
public TestFoo $nestedObject;
3234
}
3335

3436

@@ -38,3 +40,8 @@ public function __construct($constructorArgument)
3840
{
3941
}
4042
}
43+
44+
final class TestFoo
45+
{
46+
public int $int;
47+
}

0 commit comments

Comments
 (0)