Files
michaelschiemer/tests/debug/simple-cache-test.php
Michael Schiemer 55a330b223 Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
2025-08-11 20:13:26 +02:00

70 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
echo "🧪 Simple Cache Test\n";
echo "==================\n\n";
use App\Framework\Cache\CacheInitializer;
use App\Framework\Cache\CacheItem;
use App\Framework\Cache\CacheKey;
use App\Framework\Core\PathProvider;
use App\Framework\Core\ValueObjects\Duration;
use App\Framework\DateTime\SystemClock;
use App\Framework\DI\DefaultContainer;
use App\Framework\Performance\EnhancedPerformanceCollector;
try {
// Setup
$container = new DefaultContainer();
$performanceCollector = new EnhancedPerformanceCollector();
$pathProvider = new PathProvider(__DIR__ . '/../..');
$clock = new SystemClock();
$container->instance(PathProvider::class, $pathProvider);
$container->instance(EnhancedPerformanceCollector::class, $performanceCollector);
$container->instance(SystemClock::class, $clock);
echo "1. Initializing cache...\n";
$cacheInitializer = new CacheInitializer($performanceCollector, $container);
$cache = $cacheInitializer();
echo " Cache class: " . get_class($cache) . "\n";
// Test basic cache operations
echo "\n2. Testing basic cache operations...\n";
$testKey = CacheKey::fromString('test_simple');
$testData = ['hello' => 'world', 'time' => time()];
$cacheItem = CacheItem::forSetting(
key: $testKey,
value: $testData,
ttl: Duration::fromMinutes(5)
);
echo " Writing to cache...\n";
$writeResult = $cache->set($cacheItem);
echo " Write result: " . ($writeResult ? 'SUCCESS' : 'FAILED') . "\n";
echo " Reading from cache...\n";
$readResult = $cache->get($testKey);
echo " Read result class: " . get_class($readResult) . "\n";
if ($readResult->has($testKey)) {
$cachedItem = $readResult->get($testKey);
echo " Cache hit: " . ($cachedItem->isHit ? 'YES' : 'NO') . "\n";
echo " Cached value: " . json_encode($cachedItem->value) . "\n";
} else {
echo " ❌ Cache miss - key not found\n";
}
echo "\n✅ Test completed successfully!\n";
} catch (\Throwable $e) {
echo "\n❌ Error: " . $e->getMessage() . "\n";
echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}