Skip to content

Commit 4e5affe

Browse files
committed
[1.x] Test cache logging via the event, not the cache-clear controller
The /api/cache controller also runs assets:publish, which returns a non-zero exit code (409) in CI where asset publishing isn't available. Dispatch the ClearingCache event directly and assert the log entry, which tests the listener without depending on that environment-specific step.
1 parent 2675ffb commit 4e5affe

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

extensions/audit/tests/integration/CoreCacheTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,26 @@
99

1010
namespace Flarum\Audit\Tests\integration;
1111

12+
use Flarum\Audit\AuditLog;
13+
use Flarum\Foundation\Event\ClearingCache;
14+
use Illuminate\Contracts\Events\Dispatcher;
15+
1216
class CoreCacheTest extends TestCase
1317
{
1418
/**
1519
* @test
1620
*/
17-
public function web_cache_clear()
21+
public function cache_clear_is_logged()
1822
{
19-
$this->sendSuccessfulRequest('DELETE', '/api/cache', [], 204);
23+
// Dispatch the event our listener hooks directly, rather than driving the /api/cache
24+
// controller, which also runs assets:publish — a step that isn't reliably available in CI.
25+
$this->app()->getContainer()->make(Dispatcher::class)->dispatch(new ClearingCache());
26+
27+
$log = AuditLog::query()->where('action', 'cache_cleared')->first();
2028

21-
$this->assertLogExists('cache_cleared');
29+
$this->assertNotNull($log, 'A cache_cleared entry should be logged');
30+
// Dispatched outside an HTTP request, so there is no actor or IP context.
31+
$this->assertNull($log->actor_id);
32+
$this->assertNull($log->payload);
2233
}
2334
}

extensions/audit/tests/integration/TestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function setUp(): void
3434
->exemptRoute('confirmEmail.submit')
3535
->exemptRoute('savePassword')
3636
->exemptRoute('forgot')
37-
->exemptRoute('cache.clear')
3837
);
3938

4039
$this->prepareDatabase([

0 commit comments

Comments
 (0)