Files
michaelschiemer/tests/debug/test-default-strategies-enabled.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
2025-10-25 19:18:37 +02:00

229 lines
8.0 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Cache\CacheItem;
use App\Framework\Cache\CacheKey;
use App\Framework\Cache\SmartCache;
use App\Framework\Core\ValueObjects\Duration;
echo "=== Testing Default Strategies Auto-Activation ===\n\n";
// Create simple mock cache
$mockCache = new class () implements \App\Framework\Cache\Cache {
private array $storage = [];
public function get(\App\Framework\Cache\CacheIdentifier ...$identifiers): \App\Framework\Cache\CacheResult
{
$items = [];
foreach ($identifiers as $identifier) {
$key = $identifier->toString();
if (isset($this->storage[$key])) {
$items[] = \App\Framework\Cache\CacheItem::hit($identifier, $this->storage[$key]['value']);
} else {
$items[] = \App\Framework\Cache\CacheItem::miss($identifier);
}
}
return \App\Framework\Cache\CacheResult::fromItems(...$items);
}
public function set(\App\Framework\Cache\CacheItem ...$items): bool
{
foreach ($items as $item) {
$this->storage[$item->key->toString()] = [
'value' => $item->value,
'ttl' => $item->ttl,
];
}
return true;
}
public function has(\App\Framework\Cache\CacheIdentifier ...$identifiers): array
{
$results = [];
foreach ($identifiers as $identifier) {
$results[$identifier->toString()] = isset($this->storage[$identifier->toString()]);
}
return $results;
}
public function forget(\App\Framework\Cache\CacheIdentifier ...$identifiers): bool
{
foreach ($identifiers as $identifier) {
unset($this->storage[$identifier->toString()]);
}
return true;
}
public function clear(): bool
{
$this->storage = [];
return true;
}
public function remember(\App\Framework\Cache\CacheKey $key, callable $callback, ?\App\Framework\Core\ValueObjects\Duration $ttl = null): \App\Framework\Cache\CacheItem
{
$result = $this->get($key);
$item = $result->getItem($key);
if ($item->isHit) {
return $item;
}
$value = $callback();
$this->set(\App\Framework\Cache\CacheItem::forSet($key, $value, $ttl));
return \App\Framework\Cache\CacheItem::hit($key, $value);
}
};
echo "1. Testing Default Constructor Behavior:\n\n";
try {
// Create SmartCache with default constructor (should auto-enable strategies)
$smartCache = new SmartCache($mockCache);
echo " ✅ SmartCache created with default constructor\n";
// Check if strategies are enabled
$stats = $smartCache->getStats();
$strategySupport = $stats['strategy_support'] ?? false;
$strategyManager = $smartCache->getStrategyManager();
echo " 📊 Strategy support: " . ($strategySupport ? 'YES' : 'NO') . "\n";
if ($strategyManager) {
$managerStats = $strategyManager->getStats();
echo " 📊 Total strategies: {$managerStats['strategy_manager']['total_strategies']}\n";
echo " 📊 Enabled strategies: {$managerStats['strategy_manager']['enabled_strategies']}\n";
echo " 📊 Strategy names: " . implode(', ', $managerStats['strategy_manager']['strategy_names']) . "\n";
}
echo "\n";
} catch (\Throwable $e) {
echo " ❌ Error testing default constructor: {$e->getMessage()}\n\n";
}
echo "2. Testing Strategy Auto-Activation with Cache Operations:\n\n";
try {
$smartCache = new SmartCache($mockCache);
$testKey = CacheKey::fromString('auto_strategy_test');
echo " 🔧 Testing cache operations with auto-enabled strategies:\n";
// Test cache set with TTL modification by strategies
$originalTtl = Duration::fromMinutes(30);
$smartCache->set(CacheItem::forSet($testKey, "test_value", $originalTtl));
echo " ✅ Cache SET operation completed\n";
// Test cache get with strategy access tracking
$result = $smartCache->get($testKey);
$item = $result->getItem($testKey);
echo " ✅ Cache GET operation completed: " . ($item->isHit ? 'HIT' : 'MISS') . "\n";
// Test remember operation with strategy integration
$rememberResult = $smartCache->remember(
CacheKey::fromString('remember_test'),
fn () => "remembered_value",
Duration::fromHours(1)
);
echo " ✅ Cache REMEMBER operation completed: " . ($rememberResult->isHit ? 'HIT' : 'MISS') . "\n";
// Check if strategies have recorded activity
$adaptiveStats = $smartCache->getStrategyStats('adaptive_ttl');
if ($adaptiveStats) {
echo " 📊 Adaptive TTL tracked keys: {$adaptiveStats['total_tracked_keys']}\n";
}
$heatMapStats = $smartCache->getStrategyStats('heat_map');
if ($heatMapStats) {
echo " 📊 Heat Map tracked keys: {$heatMapStats['total_tracked_keys']}\n";
}
echo "\n";
} catch (\Throwable $e) {
echo " ❌ Error testing strategy auto-activation: {$e->getMessage()}\n\n";
}
echo "3. Testing Explicit Strategy Control:\n\n";
try {
// Test withoutStrategies method
echo " 🚫 Testing explicit strategy disabling:\n";
$noStrategyCache = SmartCache::withoutStrategies($mockCache);
$noStrategyStats = $noStrategyCache->getStats();
$hasStrategies = $noStrategyStats['strategy_support'] ?? false;
echo " ✅ Cache without strategies created\n";
echo " 📊 Strategy support: " . ($hasStrategies ? 'YES' : 'NO') . "\n";
// Test withDefaultStrategies method (explicit activation)
echo "\n ✨ Testing explicit strategy enabling:\n";
$explicitStrategyCache = SmartCache::withDefaultStrategies($mockCache);
$explicitStats = $explicitStrategyCache->getStats();
$explicitHasStrategies = $explicitStats['strategy_support'] ?? false;
echo " ✅ Cache with explicit strategies created\n";
echo " 📊 Strategy support: " . ($explicitHasStrategies ? 'YES' : 'NO') . "\n";
echo "\n";
} catch (\Throwable $e) {
echo " ❌ Error testing explicit strategy control: {$e->getMessage()}\n\n";
}
echo "4. Testing Performance vs Intelligence Trade-off:\n\n";
try {
echo " ⚡ Comparing cache configurations:\n";
// Without strategies (maximum performance)
$performanceCache = SmartCache::withoutStrategies($mockCache);
// With default strategies (balanced intelligence)
$intelligentCache = new SmartCache($mockCache); // Uses default strategies
// With performance strategies (performance-focused intelligence)
$perfOptimizedCache = SmartCache::withPerformanceStrategies($mockCache);
echo " ✅ Performance Cache (no strategies): Strategy support = " .
($performanceCache->getStats()['strategy_support'] ? 'YES' : 'NO') . "\n";
echo " ✅ Intelligent Cache (default strategies): Strategy support = " .
($intelligentCache->getStats()['strategy_support'] ? 'YES' : 'NO') . "\n";
echo " ✅ Performance-Optimized Cache (perf strategies): Strategy support = " .
($perfOptimizedCache->getStats()['strategy_support'] ? 'YES' : 'NO') . "\n";
echo "\n";
} catch (\Throwable $e) {
echo " ❌ Error testing performance configurations: {$e->getMessage()}\n\n";
}
echo "=== Default Strategies Auto-Activation Test Completed ===\n";
echo "\n🎯 Summary:\n";
echo " • ✅ SmartCache constructor now auto-enables Default Strategies\n";
echo " • ✅ Strategy support is active by default for intelligence\n";
echo " • ✅ SmartCache::withoutStrategies() available for maximum performance\n";
echo " • ✅ Backward compatibility maintained with explicit methods\n";
echo " • ✅ Convention over Configuration philosophy implemented\n";
echo "\n💡 Usage:\n";
echo " new SmartCache(\$cache) → WITH strategies (default)\n";
echo " SmartCache::withDefaultStrategies(\$cache) → WITH strategies (explicit)\n";
echo " SmartCache::withoutStrategies(\$cache) → WITHOUT strategies (performance)\n";