Skip to content

Commit 6e58d54

Browse files
committed
[Translator] Move already generated constants from static var to class property
Otherwise the generated constants were persisted between tests, and lead to bad constants names generation.
1 parent 18baea3 commit 6e58d54

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/Translator/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/composer.lock
44
/phpunit.xml
55
/.phpunit.result.cache
6+
7+
/var

src/Translator/src/TranslationsDumper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TranslationsDumper
3434
{
3535
private array $excludedDomains = [];
3636
private array $includedDomains = [];
37+
private array $alreadyGeneratedConstants = [];
3738

3839
public function __construct(
3940
private string $dumpDir,
@@ -184,16 +185,14 @@ private function getLocaleFallbacks(MessageCatalogueInterface ...$catalogues): a
184185

185186
private function generateConstantName(string $translationId): string
186187
{
187-
static $alreadyGenerated = [];
188-
189188
$translationId = s($translationId)->ascii()->snake()->upper()->replaceMatches('/^(\d)/', '_$1')->toString();
190189
$prefix = 0;
191190
do {
192191
$constantName = $translationId.($prefix > 0 ? '_'.$prefix : '');
193192
++$prefix;
194-
} while ($alreadyGenerated[$constantName] ?? false);
193+
} while ($this->alreadyGeneratedConstants[$constantName] ?? false);
195194

196-
$alreadyGenerated[$constantName] = true;
195+
$this->alreadyGeneratedConstants[$constantName] = true;
197196

198197
return $constantName;
199198
}

src/Translator/tests/CacheWarmer/TranslationsCacheWarmerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function setUpBeforeClass(): void
2828

2929
public static function tearDownAfterClass(): void
3030
{
31-
@unlink(self::$cacheDir);
31+
@rmdir(self::$cacheDir);
3232
}
3333

3434
public function test()

0 commit comments

Comments
 (0)