Skip to content

Commit a816abb

Browse files
committed
fix: add missing getHidden() to Log\Context\Repository stub
Laravel 12's queue handler calls getHidden() on the context repository when releasing unique-job locks after a ModelNotFoundException (CallQueuedHandler::ensureUniqueJobLockIsReleasedViaContext). Our stub implemented addHidden, forgetHidden, and allHidden but not getHidden, so any queued job whose subject was deleted between dispatch and execution turned a benign ModelNotFoundException into a cluster of fatal "Call to undefined method" errors. Add getHidden() mirroring get() for the hidden array. With nothing writing to the hidden context in a fresh worker, the call returns null and Laravel's handler silently skips lock cleanup — the intended no-op-on-empty path. Add unit coverage for the hidden-array methods. Fixes #4611
1 parent 852ffef commit a816abb

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

framework/core/src/Log/Context/Repository.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public function add(string|array $key, mixed $value = null): self
8080
return $this;
8181
}
8282

83+
/**
84+
* Get a hidden context value.
85+
*/
86+
public function getHidden(string $key, mixed $default = null): mixed
87+
{
88+
return $this->hidden[$key] ?? $default;
89+
}
90+
8391
/**
8492
* Add a hidden context value.
8593
*/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Flarum.
5+
*
6+
* For detailed copyright and license information, please view the
7+
* LICENSE file that was distributed with this source code.
8+
*/
9+
10+
namespace Flarum\Tests\unit\Log\Context;
11+
12+
use Flarum\Log\Context\Repository;
13+
use Flarum\Testing\unit\TestCase;
14+
use PHPUnit\Framework\Attributes\Test;
15+
16+
class RepositoryTest extends TestCase
17+
{
18+
#[Test]
19+
public function get_hidden_returns_stored_value()
20+
{
21+
$repository = new Repository();
22+
$repository->addHidden('foo', 'bar');
23+
24+
$this->assertSame('bar', $repository->getHidden('foo'));
25+
}
26+
27+
#[Test]
28+
public function get_hidden_returns_default_when_key_missing()
29+
{
30+
$repository = new Repository();
31+
32+
$this->assertNull($repository->getHidden('missing'));
33+
$this->assertSame('fallback', $repository->getHidden('missing', 'fallback'));
34+
}
35+
36+
#[Test]
37+
public function add_get_forget_hidden_round_trip()
38+
{
39+
$repository = new Repository();
40+
$repository->addHidden(['a' => 1, 'b' => 2]);
41+
42+
$this->assertSame(1, $repository->getHidden('a'));
43+
$this->assertSame(['a' => 1, 'b' => 2], $repository->allHidden());
44+
45+
$repository->forgetHidden('a');
46+
47+
$this->assertNull($repository->getHidden('a'));
48+
$this->assertSame(['b' => 2], $repository->allHidden());
49+
}
50+
51+
#[Test]
52+
public function hidden_data_is_isolated_from_public_data()
53+
{
54+
$repository = new Repository();
55+
$repository->add('foo', 'public');
56+
$repository->addHidden('foo', 'hidden');
57+
58+
$this->assertSame('public', $repository->get('foo'));
59+
$this->assertSame('hidden', $repository->getHidden('foo'));
60+
}
61+
}

0 commit comments

Comments
 (0)