8000 Merge branch '5.4' into 6.0 · symfony/symfony@cfdff12 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfdff12

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [String] Add tests for AsciiSlugger [Serializer] Fix get accessor regex in AnnotationLoader [HttpKernel] Fix passing `null` to `\trim()` method in LoggerDataCollector [Translation] Crowdin provider throw Exception when status is 50x Always attempt to listen for notifications add missing changelog entry for the AtLeastOneOf constraint validate nested constraints only if they are in the same group
2 parents 2340c50 + bd09cb8 commit cfdff12

File tree

20 files changed

+1505
-45
lines changed

20 files changed

+1505
-45
lines changed

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function getFilters()
144144

145145
$allChannels = [];
146146
foreach ($this->getProcessedLogs() as $log) {
147-
if ('' === trim($log['channel'])) {
147+
if ('' === trim($log['channel'] ?? '')) {
148148
continue;
149149
}
150150

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
1313

14+
use Doctrine\DBAL\Cache\ArrayResult;
15+
use Doctrine\DBAL\Cache\ArrayStatement;
16+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
17+
use Doctrine\DBAL\Query\QueryBuilder;
18+
use Doctrine\DBAL\Result;
1419
use Doctrine\DBAL\Schema\Table;
1520
use PHPUnit\Framework\TestCase;
1621
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;
@@ -42,6 +47,68 @@ public function testUnserialize()
4247
$connection->__wakeup();
4348
}
4449

50+
public function testListenOnConnection()
51+
{
52+
$driverConnection = $this->createMock(\Doctrine\DBAL F438 \Connection::class);
53+
54+
$driverConnection
55+
->expects(self::any())
56+
->method('getDatabasePlatform')
57+
->willReturn(new PostgreSQLPlatform());
58+
59+
$driverConnection
60+
->expects(self::any())
61+
->method('createQueryBuilder')
62+
->willReturn(new QueryBuilder($driverConnection));
63+
64+
$wrappedConnection = new class() {
65+
private $notifyCalls = 0;
66+
67+
public function pgsqlGetNotify()
68+
{
69+
++$this->notifyCalls;
70+
71+
return false;
72+
}
73+
74+
public function countNotifyCalls()
75+
{
76+
return $this->notifyCalls;
77+
}
78+
};
79+
80+
// dbal 2.x
81+
if (interface_exists(Result::class)) {
82+
$driverConnection
83+
->expects(self::exactly(2))
84+
->method('getWrappedConnection')
85+
->willReturn($wrappedConnection);
86+
87+
$driverConnection
88+
->expects(self::any())
89+
->method('executeQuery')
90+
->willReturn(new ArrayStatement([]));
91+
} else {
92+
// dbal 3.x
93+
$driverConnection
94+
->expects(self::exactly(2))
95+
->method('getNativeConnection')
96+
->willReturn($wrappedConnection);
97+
98+
$driverConnection
99+
->expects(self::any())
100+
->method('executeQuery')
101+
->willReturn(new Result(new ArrayResult([]), $driverConnection));
102+
}
103+
$connection = new PostgreSqlConnection(['table_name' => 'queue_table'], $driverConnection);
104+
105+
$connection->get(); // first time we have queueEmptiedAt === null, fallback on the parent implementation
106+
$connection->get();
107+
$connection->get();
108+
109+
$this->assertSame(2, $wrappedConnection->countNotifyCalls());
110+
}
111+
45112
public function testGetExtraSetupSql()
46113
{
47114
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ final class PostgreSqlConnection extends Connection
3333
'get_notify_timeout' => 0,
3434
];
3535

36-
private bool $listening = false;
37-
3836
public function __sleep(): array
3937
{
4038
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
@@ -62,12 +60,9 @@ public function get(): ?array
6260
return parent::get();
6361
}
6462

65-
if (!$this->listening) {
66-
// This is secure because the table name must be a valid identifier:
67-
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
68-
$this->executeStatement(sprintf('LISTEN "%s"', $this->configuration['table_name']));
69-
$this->listening = true;
70-
}
63+
// This is secure because the table name must be a valid identifier:
64+
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
65+
$this->executeStatement(sprintf('LISTEN "%s"', $this->configuration['table_name']));
7166

7267
if (method_exists($this->driverConnection, 'getNativeConnection')) {
7368
$wrappedConnection = $this->driverConnection->getNativeConnection();
@@ -150,11 +145,6 @@ private function createTriggerFunctionName(): string
150145

151146
private function unlisten()
152147
{
153-
if (!$this->listening) {
154-
return;
155-
}
156-
157148
$this->executeStatement(sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
158-
$this->listening = false;
159149
}
160150
}

src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
100100
continue;
101101
}
102102

103-
$getAccessor = preg_match('/^(get|)(.+)$/i', $method->name);
104-
if ($getAccessor && 0 !== $method->getNumberOfRequiredParameters()) {
103+
if (0 === stripos($method->name, 'get') && $method->getNumberOfRequiredParameters()) {
105104
continue; /* matches the BC behavior in `Symfony\Component\Serializer\Normalizer\ObjectNormalizer::extractAttributes` */
106105
}
107106

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/IgnoreDummyAdditionalGetter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public function getExtraValue(string $parameter)
2020
{
2121
return $parameter;
2222
}
23+
24+
public function setExtraValue2(string $parameter)
25+
{
26+
}
2327
}

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ public function getExtraValue(string $parameter)
1515
{
1616
return $parameter;
1717
}
18+
19+
public function setExtraValue2(string $parameter)
20+
{
21+
}
1822
}

src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/IgnoreDummyAdditionalGetter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ public function getExtraValue(string $parameter)
1818
{
1919
return $parameter;
2020
}
21+
22+
public function setExtraValue2(string $parameter)
23+
{
24+
}
2125
}

src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ public function getExtraValue(string $parameter)
1515
{
1616
return $parameter;
1717
}
18+
19+
public function setExtraValue2(string $parameter)
20+
{
21+
}
1822
}

src/Symfony/Component/Serializer/Tests/Mapping/Loader/AnnotationLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsUsed()
157157

158158
$attributes = $classMetadata->getAttributesMetadata();
159159
self::assertArrayNotHasKey('extraValue', $attributes);
160+
self::assertArrayHasKey('extraValue2', $attributes);
160161
}
161162

162163
public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsNotUsed()
@@ -166,6 +167,7 @@ public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsNotUsed
166167

167168
$attributes = $classMetadata->getAttributesMetadata();
168169
self::assertArrayNotHasKey('extraValue', $attributes);
170+
self::assertArrayHasKey('extraValue2', $attributes);
169171
}
170172

171173
abstract protected function createLoader(): AnnotationLoader;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\String;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\String\Slugger\AsciiSlugger;
16+
17+
class AsciiSluggerTest extends TestCase
18+
{
19+
public function provideSlugTests(): iterable
20+
{
21+
yield ['', ''];
22+
yield ['foo', ' foo '];
23+
yield ['foo-bar', 'foo bar'];
24+
25+
yield ['foo-bar', 'foo@bar', '-'];
26+
yield ['foo-at-bar', 'foo@bar', '-', 'en'];
27+
28+
yield ['e-a', 'é$!à'];
29+
yield ['e_a', 'é$!à', '_'];
30+
31+
yield ['a', 'ä'];
32+
yield ['a', 'ä', '-', 'fr'];
33+
yield ['ae', 'ä', '-', 'de'];
34+
yield ['ae', 'ä', '-', 'de_fr']; // Ensure we get the parent locale
35+
yield ['g', 'ғ', '-'];
36+
yield ['gh', 'ғ', '-', 'uz'];
37+
yield ['gh', 'ғ', '-', 'uz_fr']; // Ensure we get the parent locale
38+
}
39+
40+
/** @dataProvider provideSlugTests */
41+
public function testSlug(string $expected, string $string, string $separator = '-', string $locale = null)
42+
{
43+
$slugger = new AsciiSlugger();
44+
45+
$this->assertSame($expected, (string) $slugger->slug($string, $separator, $locale));
46+
}
47+
}

src/Symfony/Component/Translation/Bridge/Crowdin/CrowdinProvider.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ public function write(TranslatorBagInterface $translatorBag): void
9595
}
9696

9797
foreach ($responses as $response) {
98-
if (200 !== $response->getStatusCode()) {
98+
if (200 !== $statusCode = $response->getStatusCode()) {
9999
$this->logger->error(sprintf('Unable to upload translations to Crowdin: "%s".', $response->getContent(false)));
100+
101+
if (500 <= $statusCode) {
102+
throw new ProviderException('Unable to upload translations to Crowdin.', $response);
103+
}
100104
}
101105
}
102106
}
@@ -135,9 +139,13 @@ public function read(array $domains, array $locales): TranslatorBag
135139
continue;
136140
}
137141

138-
if (200 !== $response->getStatusCode()) {
142+
if (200 !== $statusCode = $response->getStatusCode()) {
139143
$this->logger->error(sprintf('Unable to export file: "%s".', $response->getContent(false)));
140144

145+
if (500 <= $statusCode) {
146+
throw new ProviderException('Unable to export file.', $response);
147+
}
148+
141149
continue;
142150
}
143151

@@ -146,9 +154,13 @@ public function read(array $domains, array $locales): TranslatorBag
146154
}
147155

148156
foreach ($downloads as [$response, $locale, $domain]) {
149-
if (200 !== $response->getStatusCode()) {
157+
if (200 !== $statusCode = $response->getStatusCode()) {
150158
$this->logger->error(sprintf('Unable to download file content: "%s".', $response->getContent(false)));
151159

160+
if (500 <= $statusCode) {
161+
throw new ProviderException('Unable to download file content.', $response);
162+
}
163+
152164
continue;
153165
}
154166

@@ -192,8 +204,12 @@ public function delete(TranslatorBagInterface $translatorBag): void
192204
continue;
193205
}
194206

195-
if (204 !== $response->getStatusCode()) {
207+
if (204 !== $statusCode = $response->getStatusCode()) {
196208
$this->logger->warning(sprintf('Unable to delete string: "%s".', $response->getContent(false)));
209+
210+
if (500 <= $statusCode) {
211+
throw new ProviderException('Unable to delete string.', $response);
212+
}
197213
}
198214
}
199215
}
@@ -238,9 +254,13 @@ private function addFile(string $domain, string $content): ?array
238254
],
239255
]);
240256

241-
if (201 !== $response->getStatusCode()) {
257+
if (201 !== $statusCode = $response->getStatusCode()) {
242258
$this->logger->error(sprintf('Unable to create a File in Crowdin for domain "%s": "%s".', $domain, $response->getContent(false)));
243259

260+
if (500 <= $statusCode) {
261+
throw new ProviderException(sprintf('Unable to create a File in Crowdin for domain "%s".', $domain), $response);
262+
}
263+
244264
return null;
245265
}
246266

@@ -261,9 +281,13 @@ private function updateFile(int $fileId, string $domain, string $content): ?arra
261281
],
262282
]);
263283

264-
if (200 !== $response->getStatusCode()) {
284+
if (200 !== $statusCode = $response->getStatusCode()) {
265285
$this->logger->error(sprintf('Unable to update file in Crowdin for file ID "%d" and domain "%s": "%s".', $fileId, $domain, $response->getContent(false)));
266286

287+
if (500 <= $statusCode) {
288+
throw new ProviderException(sprintf('Unable to update file in Crowdin for file ID "%d" and domain "%s".', $fileId, $domain), $response);
289+
}
290+
267291
return null;
268292
}
269293

@@ -324,9 +348,7 @@ private function listStrings(int $fileId, int $limit, int $offset): array
324348
]);
325349

326350
if (200 !== $response->getStatusCode()) {
327-
$this->logger->error(sprintf('Unable to list strings for file %d: "%s".', $fileId, $response->getContent()));
328-
329-
return [];
351+
throw new ProviderException(sprintf('Unable to list strings for file "%d".', $fileId), $response);
330352
}
331353

332354
return $response->toArray()['data'];

0 commit comments

Comments
 (0)
0