toString(); if (isset($this->data[$key])) { $value = $this->data[$key]; $hits[$key] = $value instanceof CacheItem ? $value->value : $value; } else { $misses[] = $key; } } return new CacheResult($hits, $misses); } public function set(CacheItem ...$items): bool { foreach ($items as $item) { $this->data[$item->key->toString()] = $item; } return true; } public function has(CacheIdentifier ...$identifiers): array { return []; } public function forget(CacheIdentifier ...$identifiers): bool { return true; } public function clear(): bool { $this->data = []; return true; } public function remember(CacheKey $key, callable $callback, ?Duration $ttl = null): CacheItem { $keyStr = $key->toString(); if (isset($this->data[$keyStr])) { return $this->data[$keyStr]; } $value = $callback(); $item = CacheItem::forSetting($key, $value, $ttl); $this->data[$keyStr] = $item; return $item; } }; // Create test clock $clock = new class implements Clock { public function now(): \DateTimeImmutable { return new \DateTimeImmutable(); } public function fromTimestamp(Timestamp $timestamp): \DateTimeImmutable { return $timestamp->toDateTime(); } public function fromString(string $dateTime, ?string $format = null): \DateTimeImmutable { return new \DateTimeImmutable($dateTime); } public function today(): \DateTimeImmutable { return new \DateTimeImmutable('today'); } public function yesterday(): \DateTimeImmutable { return new \DateTimeImmutable('yesterday'); } public function tomorrow(): \DateTimeImmutable { return new \DateTimeImmutable('tomorrow'); } public function time(): Timestamp { return Timestamp::now(); } }; echo "Creating components...\n"; $storage = new InMemoryErrorStorage(); $alertQueue = new InMemoryQueue(); // Create exception and context $exception = FrameworkException::create( DatabaseErrorCode::QUERY_FAILED, 'Test database query failed' ); $exceptionContext = ExceptionContext::empty() ->withOperation('test_operation', 'TestComponent') ->withData([ 'test_key' => 'test_value', 'original_exception' => $exception, 'exception_message' => $exception->getMessage() ]); $requestContext = RequestContext::fromGlobals(); $systemContext = SystemContext::current(); $errorHandlerContext = ErrorHandlerContext::create( $exceptionContext, $requestContext, $systemContext, ['http_status' => 500] ); echo "Creating ErrorEvent...\n"; $errorEvent = ErrorEvent::fromErrorHandlerContext($errorHandlerContext, $clock); echo " Event fingerprint: " . $errorEvent->getFingerprint() . "\n"; echo "\nManually simulating updateErrorPattern logic...\n"; $fingerprint = $errorEvent->getFingerprint(); $cacheKey = "error_pattern:" . $fingerprint; echo "1. Checking cache for key: {$cacheKey}\n"; $cacheResult = $cache->get(CacheKey::fromString($cacheKey)); if ($cacheResult->isHit()) { echo " Cache HIT - pattern exists in cache\n"; $pattern = ErrorPattern::fromArray($cacheResult->hits[$cacheKey]); } else { echo " Cache MISS - checking storage\n"; echo "2. Checking storage for fingerprint: {$fingerprint}\n"; $pattern = $storage->getPatternByFingerprint($fingerprint); if ($pattern === null) { echo " No pattern in storage - creating new one\n"; echo "3. Creating new pattern from event...\n"; try { $pattern = ErrorPattern::fromErrorEvent($errorEvent, $clock); echo " Pattern created successfully! ID: " . (string) $pattern->id . "\n"; } catch (\Throwable $e) { echo " ERROR creating pattern: " . $e->getMessage() . "\n"; echo " Exception: " . get_class($e) . "\n"; exit(1); } } else { echo " Pattern found in storage - updating\n"; $pattern = $pattern->withNewOccurrence($errorEvent); } } echo "4. Storing pattern...\n"; try { $storage->storePattern($pattern); echo " Pattern stored successfully\n"; } catch (\Throwable $e) { echo " ERROR storing pattern: " . $e->getMessage() . "\n"; echo " Exception: " . get_class($e) . "\n"; exit(1); } echo "5. Caching pattern...\n"; try { $cacheItem = CacheItem::forSetting( CacheKey::fromString($cacheKey), $pattern->toArray(), Duration::fromSeconds(3600) ); $cache->set($cacheItem); echo " Pattern cached successfully\n"; } catch (\Throwable $e) { echo " ERROR caching pattern: " . $e->getMessage() . "\n"; echo " Exception: " . get_class($e) . "\n"; exit(1); } echo "\n6. Verifying pattern is retrievable...\n"; $activePatterns = $storage->getActivePatterns(10); echo " Active patterns count: " . count($activePatterns) . "\n"; if (count($activePatterns) > 0) { echo "\n✓ SUCCESS: Pattern creation flow works!\n"; } else { echo "\n✗ ERROR: Pattern was stored but not retrieved\n"; }