Skip to content

Commit 127efbf

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: consistently use dates in UTC in Doctrine connection tests [Translation] Crowdin Bridge: use the project language mapping [DoctrineBridge] Adapt deprecation message to include ODM bundle attribute name Added missing Serbian (sr_Cyrl) translation [Validator] Add missing Serbian translation [Validator] Add missing arabic translation [Validator] updated Albanian translation [Clock] Fix calling `mockTime()` in `setUpBeforeClass()`
2 parents aad8531 + f6ec599 commit 127efbf

File tree

12 files changed

+324
-166
lines changed

12 files changed

+324
-166
lines changed

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ private function initializeSubscribers(): void
207207
if (\is_string($listener)) {
208208
$listener = $this->container->get($listener);
209209
}
210-
// throw new \InvalidArgumentException(sprintf('Using Doctrine subscriber "%s" is not allowed, declare it as a listener instead.', \is_object($listener) ? $listener::class : $listener));
211-
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener);
210+
// throw new \InvalidArgumentException(sprintf('Using Doctrine subscriber "%s" is not allowed. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.', \is_object($listener) ? $listener::class : $listener));
211+
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener);
212212
parent::addEventSubscriber($listener);
213213
}
214214
}

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private function addTaggedServices(ContainerBuilder $container): array
105105
$refs = $managerDef->getArguments()[1] ?? [];
106106
$listenerRefs[$con][$id] = new Reference($id);
107107
if ($subscriberTag === $tagName) {
108-
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.', $id);
108+
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[%s] attribute.', $id, str_starts_with($this->tagPrefix, 'doctrine_mongodb') ? 'AsDocumentListener' : 'AsDoctrineListener');
109109
$refs[] = $id;
110110
} else {
111111
$refs[] = [[$tag['event']], $id];

src/Symfony/Bridge/Doctrine/Tests/ContainerAwareEventManagerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testDispatchEventRespectOrderWithSubscribers()
5050
$this->container->set('sub1', $subscriber1 = new MySubscriber(['foo']));
5151
$this->container->set('sub2', $subscriber2 = new MySubscriber(['foo']));
5252

53-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
53+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.');
5454
$this->assertSame([$subscriber1, $subscriber2], array_values($this->evm->getListeners('foo')));
5555
}
5656

@@ -92,7 +92,7 @@ public function testDispatchEventWithSubscribers()
9292
$this->assertSame(0, $subscriber1->calledSubscribedEventsCount);
9393

9494
$this->container->set('lazy1', $listener1 = new MyListener());
95-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
95+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.');
9696
$this->evm->addEventListener('foo', 'lazy1');
9797
$this->evm->addEventListener('foo', $listener2 = new MyListener());
9898
$this->evm->addEventSubscriber($subscriber2 = new MySubscriber(['bar']));
@@ -177,7 +177,7 @@ public function testAddEventListenerAndSubscriberAfterDispatchEvent()
177177
$this->assertSame(0, $subscriber1->calledSubscribedEventsCount);
178178

179179
$this->container->set('lazy1', $listener1 = new MyListener());
180-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
180+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.');
181181
$this->evm->addEventListener('foo', 'lazy1');
182182
$this->assertSame(1, $subscriber1->calledSubscribedEventsCount);
183183

@@ -238,7 +238,7 @@ public function testGetListenersForEventWhenSubscribersArePresent()
238238

239239
$this->container->set('lazy', $listener1 = new MyListener());
240240
$this->container->set('lazy2', $subscriber1 = new MySubscriber(['foo']));
241-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
241+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.');
242242
$this->evm->addEventListener('foo', 'lazy');
243243
$this->evm->addEventListener('foo', $listener2 = new MyListener());
244244

src/Symfony/Component/Clock/Test/ClockSensitiveTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,20 @@ public static function mockTime(string|\DateTimeImmutable|bool $when = true): Cl
4242
}
4343

4444
/**
45+
* @beforeClass
46+
*
4547
* @before
4648
*
4749
* @internal
4850
*/
49-
protected static function saveClockBeforeTest(bool $save = true): ClockInterface
51+
public static function saveClockBeforeTest(bool $save = true): ClockInterface
5052
{
5153
static $originalClock;
5254

55+
if ($save && $originalClock) {
56+
self::restoreClockAfterTest();
57+
}
58+
5359
return $save ? $originalClock = Clock::get() : $originalClock;
5460
}
5561

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\Clock\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Psr\Clock\ClockInterface;
16+
use Symfony\Component\Clock\Clock;
17+
use Symfony\Component\Clock\MockClock;
18+
use Symfony\Component\Clock\NativeClock;
19+
use Symfony\Component\Clock\Test\ClockSensitiveTrait;
20+
21+
class ClockBeforeClassTest extends TestCase
22+
{
23+
use ClockSensitiveTrait;
24+
25+
private static ?ClockInterface $clock = null;
26+
27+
public static function setUpBeforeClass(): void
28+
{
29+
self::$clock = self::mockTime();
30+
}
31+
32+
public static function tearDownAfterClass(): void
33+
{
34+
self::$clock = null;
35+
}
36+
37+
public function testMockClock()
38+
{
39+
$this->assertInstanceOf(MockClock::class, self::$clock);
40+
$this->assertInstanceOf(NativeClock::class, Clock::get());
41+
42+
$clock = self::mockTime();
43+
$this->assertInstanceOf(MockClock::class, Clock::get());
44+
$this->assertSame(Clock::get(), $clock);
45+
46+
$this->assertNotSame($clock, self::$clock);
47+
48+
self::restoreClockAfterTest();
49+
self::saveClockBeforeTest();
50+
51+
$this->assertInstanceOf(MockClock::class, self::$clock);
52+
$this->assertInstanceOf(NativeClock::class, Clock::get());
53+
54+
$clock = self::mockTime();
55+
$this->assertInstanceOf(MockClock::class, Clock::get());
56+
$this->assertSame(Clock::get(), $clock);
57+
58+
$this->assertNotSame($clock, self::$clock);
59+
}
60+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function testSendWithDelay()
6767
// DBAL 2 compatibility
6868
$result = method_exists($qb, 'executeQuery') ? $qb->executeQuery() : $qb->execute();
6969

70-
$availableAt = new \DateTimeImmutable($result->fetchOne());
70+
$availableAt = new \DateTimeImmutable($result->fetchOne(), , new \DateTimeZone('UTC'));
7171

72-
$now = new \DateTimeImmutable('now + 60 seconds');
72+
$now = new \DateTimeImmutable('now + 60 seconds', new \DateTimeZone('UTC'));
7373
$this->assertGreaterThan($now, $availableAt);
7474
}
7575

@@ -86,9 +86,9 @@ public function testSendWithNegativeDelay()
8686
// DBAL 2 compatibility
8787
$result = method_exists($qb, 'executeQuery') ? $qb->executeQuery() : $qb->execute();
8888

89-
$availableAt = new \DateTimeImmutable($result->fetchOne());
89+
$availableAt = new \DateTimeImmutable($result->fetchOne(), new \DateTimeZone('UTC'));
9090

91-
$now = new \DateTimeImmutable('now - 60 seconds');
91+
$now = new \DateTimeImmutable('now - 60 seconds', new \DateTimeZone('UTC'));
9292
$this->assertLessThan($now, $availableAt);
9393
}
9494

@@ -170,7 +170,7 @@ public function testItCountMessages()
170170
public function testItRetrieveTheMessageThatIsOlderThanRedeliverTimeout()
171171
{
172172
$this->connection->setup();
173-
$twoHoursAgo = new \DateTimeImmutable('now -2 hours');
173+
$twoHoursAgo = new \DateTimeImmutable('now -2 hours', new \DateTimeZone('UTC'));
174174
$this->driverConnection->insert('messenger_messages', [
175175
'body' => '{"message": "Hi requeued"}',
176176
'headers' => json_encode(['type' => DummyMessage::class]),

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

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ public function __toString(): string
5656
public function write(TranslatorBagInterface $translatorBag): void
5757
{
5858
$fileList = $this->getFileList();
59+
$languageMapping = $this->getLanguageMapping();
5960

6061
$responses = [];
6162

6263
foreach ($translatorBag->getCatalogues() as $catalogue) {
64+
$locale = $catalogue->getLocale();
65+
6366
foreach ($catalogue->getDomains() as $domain) {
6467
if (0 === \count($catalogue->all($domain))) {
6568
continue;
@@ -86,7 +89,7 @@ public function write(TranslatorBagInterface $translatorBag): void
8689
continue;
8790
}
8891

89-
$responses[] = $this->uploadTranslations($fileId, $domain, $content, $catalogue->getLocale());
92+
$responses[] = $this->uploadTranslations($fileId, $domain, $content, $languageMapping[$locale] ?? $locale);
9093
}
9194
}
9295
}
@@ -105,12 +108,11 @@ public function write(TranslatorBagInterface $translatorBag): void
105108
public function read(array $domains, array $locales): TranslatorBag
106109
{
107110
$fileList = $this->getFileList();
111+
$languageMapping = $this->getLanguageMapping();
108112

109113
$translatorBag = new TranslatorBag();
110114
$responses = [];
111115

112-
$localeLanguageMap = $this->mapLocalesToLanguageId($locales);
113-
114116
foreach ($domains as $domain) {
115117
$fileId = $this->getFileIdByDomain($fileList, $domain);
116118

@@ -120,7 +122,7 @@ public function read(array $domains, array $locales): TranslatorBag
120122

121123
foreach ($locales as $locale) {
122124
if ($locale !== $this->defaultLocale) {
123-
$response = $this->exportProjectTranslations($localeLanguageMap[$locale], $fileId);
125+
$response = $this->exportProjectTranslations($languageMapping[$locale] ?? $locale, $fileId);
124126
} else {
125127
$response = $this->downloadSourceFile($fileId);
126128
}
@@ -406,37 +408,24 @@ private function getFileList(): array
406408
return $result;
407409
}
408410

409-
private function mapLocalesToLanguageId(array $locales): array
411+
private function getLanguageMapping(): array
410412
{
411413
/**
412-
* We cannot query by locales, we need to fetch all and filter out the relevant ones.
413-
*
414-
* @see https://developer.crowdin.com/api/v2/#operation/api.languages.getMany (Crowdin API)
415-
* @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.languages.getMany (Crowdin Enterprise API)
414+
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.get (Crowdin API)
415+
* @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.get (Crowdin Enterprise API)
416416
*/
417-
$response = $this->client->request('GET', '../../languages?limit=500');
417+
$response = $this->client->request('GET', '');
418418

419419
if (200 !== $response->getStatusCode()) {
420-
throw new ProviderException('Unable to list set languages.', $response);
420+
throw new ProviderException('Unable to get project info.', $response);
421421
}
422422

423-
$localeLanguageMap = [];
424-
foreach ($response->toArray()['data'] as $language) {
425-
foreach (['locale', 'osxLocale', 'id'] as $key) {
426-
if (\in_array($language['data'][$key], $locales, true)) {
427-
$localeLanguageMap[$language['data'][$key]] = $language['data']['id'];
428-
}
429-
}
430-
}
431-
432-
if (\count($localeLanguageMap) !== \count($locales)) {
433-
$message = implode('", "', array_diff($locales, array_keys($localeLanguageMap)));
434-
$message = sprintf('Unable to find all requested locales: "%s" not found.', $message);
435-
$this->logger->error($message);
436-
437-
throw new ProviderException($message, $response);
423+
$projectInfo = $response->toArray()['data'];
424+
$mapping = [];
425+
foreach ($projectInfo['languageMapping'] ?? [] as $key => $value) {
426+
$mapping[$value['locale']] = $key;
438427
}
439428

440-
return $localeLanguageMap;
429+
return $mapping;
441430
}
442431
}

0 commit comments

Comments
 (0)