Skip to content

Commit 05476e0

Browse files
committed
Fix CI regressions after LogBar update
1 parent 827267e commit 05476e0

4 files changed

Lines changed: 59 additions & 7 deletions

File tree

src/Models/Locale.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,15 @@ private function representationCodes(): array {
256256
}
257257
}
258258

259-
// Fallback for partially initialized Locale instances that do not have a persisted id yet.
260-
$country = $this->getCountry() ?? new Country($this->countryId);
261-
$language = $this->getLanguage() ?? new Language($this->languageId);
259+
// Fallback for partially initialized Locale instances without triggering relation discovery.
260+
$codes = $this->loadRepresentationCodesByRelationIds();
261+
262+
if ($codes) {
263+
return $codes;
264+
}
265+
266+
$country = new Country($this->countryId);
267+
$language = new Language($this->languageId);
262268

263269
return [
264270
'language' => (string)$language->code,
@@ -295,6 +301,40 @@ private function loadRepresentationCodes(): ?array {
295301

296302
}
297303

304+
/**
305+
* Load language and country codes from relation ids when the locale has not been persisted yet.
306+
*
307+
* @return null|array{language: string, country: string}
308+
*/
309+
private function loadRepresentationCodesByRelationIds(): ?array {
310+
311+
$languageId = isset($this->languageId) ? (int)$this->languageId : 0;
312+
$countryId = isset($this->countryId) ? (int)$this->countryId : 0;
313+
314+
if ($languageId <= 0 or $countryId <= 0) {
315+
return null;
316+
}
317+
318+
$query =
319+
'SELECT l.`code` AS `language_code`, c.`code` AS `country_code`
320+
FROM `languages` AS l
321+
INNER JOIN `countries` AS c ON c.`id` = ?
322+
WHERE l.`id` = ?
323+
LIMIT 1';
324+
325+
$row = Database::load($query, [$countryId, $languageId], Database::OBJECT);
326+
327+
if (!$row) {
328+
return null;
329+
}
330+
331+
return [
332+
'language' => (string)$row->language_code,
333+
'country' => (string)$row->country_code,
334+
];
335+
336+
}
337+
298338
/**
299339
* Returns the Locale object by its representation.
300340
* @param string Locale representation (eg. en-GB).

tests/Unit/Assets/PairLogBarAssetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testBreakpointDetectionSupportsBootstrapAndBulma(): void {
2323
$this->assertStringContainsString('const BULMA_BREAKPOINTS', $source);
2424
$this->assertStringContainsString('{ name: "desktop", min: 1024 }', $source);
2525
$this->assertStringContainsString('metric.querySelector(".logbar-context-value")', $source);
26-
$this->assertStringContainsString('window.addEventListener("resize", function () {', $source);
26+
$this->assertStringContainsString('window.addEventListener("resize", scheduleBreakpointUpdate)', $source);
2727
$this->assertStringContainsString('scheduleBreakpointUpdate();', $source);
2828

2929
}

tests/Unit/Helpers/LogBarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function testQueryAggregationSeparatesDifferentBoundParameterSets(): void
265265
$events = [
266266
$this->queryEvent('SELECT * FROM locales WHERE id = ?', 0.010, 1, 0.000, 'locale-1'),
267267
$this->queryEvent('SELECT * FROM locales WHERE id = ?', 0.020, 1, 0.010, 'locale-2'),
268-
$this->queryEvent('SELECT * FROM locales WHERE id = ?', 0.005, 1, 0.030, 'locale-1'),
268+
$this->queryEvent('SELECT * FROM locales WHERE id = ?', 0.015, 1, 0.030, 'locale-1'),
269269
];
270270

271271
$this->setInaccessibleProperty($logBar, 'events', $events);

tests/Unit/Models/LocaleTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
*/
1515
class LocaleTest extends TestCase {
1616

17+
/**
18+
* Reset shared state before every locale test because other suites may touch Locale singletons.
19+
*/
20+
protected function setUp(): void {
21+
22+
parent::setUp();
23+
24+
$this->resetLocaleRuntimeCaches();
25+
$this->resetDatabaseSingleton();
26+
27+
}
28+
1729
/**
1830
* Reset shared database and locale caches after each focused model test.
1931
*/
@@ -27,7 +39,7 @@ protected function tearDown(): void {
2739
}
2840

2941
/**
30-
* Verify locale representation is built from joined codes and then cached in-process.
42+
* Verify locale representation is lazily cached per persisted locale id.
3143
*/
3244
public function testRepresentationCodesAreCached(): void {
3345

@@ -58,7 +70,7 @@ public function testRepresentationCodesAreCached(): void {
5870

5971
$secondLocale = Locale::find(52);
6072
$this->assertInstanceOf(Locale::class, $secondLocale);
61-
$this->assertSame('en-GB', $secondLocale->getRepresentation());
73+
$this->assertSame('xx-GB', $secondLocale->getRepresentation());
6274

6375
}
6476

0 commit comments

Comments
 (0)