Die Cache-Integration war für WP Super Cache gebaut, eingesetzt wird aber WP Fastest Cache. Profil (wpfc), Listener, Drosselung, lit/cache-clear und Leeren-Probe laufen jetzt über die öffentlichen WPFC-Funktionen wpfc_clear_post_cache_by_id/wpfc_clear_all_cache; die Probe leert nur die Wegwerf-Seite (singleDeleteCache ohne Elternseiten) und prüft, dass WPFC den Hook noch verarbeitet. Smoke fastest-cache-smoke.sh ersetzt den WPSC-Smoke. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\FastestCache;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Integrations\FastestCache\FastestCacheFeature;
|
|
use LIT\MCP\Integrations\FastestCache\FastestCachePurger;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
|
|
final class FastestCachePurgerTest extends TestCase
|
|
{
|
|
public function testALockedWholePurgeDoesNothingAndSaysSo(): void
|
|
{
|
|
$previous = ini_set('error_log', '/dev/null');
|
|
Functions\expect('get_transient')->never();
|
|
$purger = new FastestCachePurger(
|
|
static fn (FastestCacheFeature $feature): bool => false,
|
|
static fn (): bool => true,
|
|
static fn (int $id) => self::fail('no post purge'),
|
|
static fn () => self::fail('no whole purge')
|
|
);
|
|
|
|
self::assertSame(FastestCachePurger::LOCKED, $purger->everything());
|
|
self::assertFalse($purger->post(3));
|
|
ini_set('error_log', (string) $previous);
|
|
}
|
|
|
|
public function testThrottledReadsTheStamp(): void
|
|
{
|
|
$stamp = false;
|
|
Functions\when('get_transient')->alias(static function () use (&$stamp) {
|
|
return $stamp;
|
|
});
|
|
$purger = new FastestCachePurger(static fn (): bool => true);
|
|
|
|
self::assertFalse($purger->throttled());
|
|
$stamp = (string) (time() - 5);
|
|
self::assertTrue($purger->throttled());
|
|
$stamp = time() - 31;
|
|
self::assertFalse($purger->throttled());
|
|
}
|
|
|
|
/** The stamp is read once: a transient expiring between two reads must not schedule the trailing purge in 1970. */
|
|
public function testEverythingReadsTheStampOnceAndSchedulesTheTrailingPurgeInTheFuture(): void
|
|
{
|
|
$reads = 0;
|
|
$scheduledAt = [];
|
|
Functions\when('get_transient')->alias(static function () use (&$reads) {
|
|
return ++$reads === 1 ? time() - 5 : false;
|
|
});
|
|
Functions\when('wp_next_scheduled')->justReturn(false);
|
|
Functions\when('wp_schedule_single_event')->alias(static function (int $at) use (&$scheduledAt): bool {
|
|
$scheduledAt[] = $at;
|
|
|
|
return true;
|
|
});
|
|
$purger = new FastestCachePurger(static fn (): bool => true);
|
|
|
|
self::assertSame(FastestCachePurger::THROTTLED, $purger->everything());
|
|
|
|
self::assertSame(1, $reads);
|
|
self::assertCount(1, $scheduledAt);
|
|
self::assertGreaterThanOrEqual(time(), $scheduledAt[0]);
|
|
}
|
|
}
|