Files
michaelschiemer/tests/debug/test-initializer-discovery.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

133 lines
4.7 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Cache\Driver\InMemoryCache;
use App\Framework\Cache\GeneralCache;
use App\Framework\Core\PathProvider;
use App\Framework\DateTime\SystemClock;
use App\Framework\DI\DefaultContainer;
use App\Framework\DI\InitializerMapper;
use App\Framework\Discovery\UnifiedDiscoveryService;
use App\Framework\Discovery\ValueObjects\DiscoveryConfiguration;
use App\Framework\Filesystem\FileSystemService;
use App\Framework\Reflection\CachedReflectionProvider;
use App\Framework\Serializer\Json\JsonSerializer;
echo "=== Testing Initializer Discovery ===\n\n";
try {
// Setup with correct path
$projectRoot = dirname(__DIR__, 2); // Go up from tests/debug to project root
$srcPath = $projectRoot . '/src';
echo "Project root: $projectRoot\n";
echo "Source path: $srcPath\n";
echo "Source path exists: " . (is_dir($srcPath) ? 'Yes' : 'No') . "\n\n";
$container = new DefaultContainer();
$pathProvider = new PathProvider($projectRoot);
$clock = new SystemClock();
$fileSystemService = new FileSystemService();
$reflectionProvider = new CachedReflectionProvider();
// Create cache for discovery
$cacheDriver = new InMemoryCache();
$serializer = new JsonSerializer();
$cache = new GeneralCache($cacheDriver, $serializer);
// Create InitializerMapper
$initializerMapper = new InitializerMapper();
// Configure discovery for the entire src directory
$config = new DiscoveryConfiguration(
paths: [$srcPath],
attributeMappers: [$initializerMapper],
targetInterfaces: [],
useCache: false
);
// Create discovery service
$discoveryService = new UnifiedDiscoveryService(
pathProvider: $pathProvider,
cache: $cache,
clock: $clock,
reflectionProvider: $reflectionProvider,
configuration: $config,
attributeMappers: [$initializerMapper],
targetInterfaces: []
);
echo "Starting discovery scan...\n";
echo "Scanning path: $srcPath\n";
echo "Path exists: " . (is_dir($srcPath) ? 'Yes' : 'No') . "\n";
// Check if path has PHP files
$phpFiles = glob($srcPath . '/**/*.php', GLOB_BRACE);
echo "PHP files found in path: " . count($phpFiles) . "\n";
if (count($phpFiles) > 0) {
echo "First few files:\n";
foreach (array_slice($phpFiles, 0, 5) as $file) {
echo " - $file\n";
}
}
$registry = $discoveryService->discover();
echo "\nDiscovery completed!\n\n";
echo "=== Discovery Results ===\n";
echo "Total registry count: " . count($registry) . "\n";
echo "Attributes registry count: " . count($registry->attributes) . "\n\n";
// Check for Initializers in attribute registry
$initializerAttributeClass = 'App\\Framework\\DI\\Initializer';
// Check if the attribute registry has the method
if (method_exists($registry->attributes, 'get')) {
$initializers = $registry->attributes->get($initializerAttributeClass);
echo "=== Initializer Results ===\n";
echo "Initializers found: " . count($initializers) . "\n\n";
if (empty($initializers)) {
echo "❌ No initializers found!\n\n";
// Try to show what's actually in the registry
echo "=== Debug: Registry Structure ===\n";
echo "Registry class: " . get_class($registry) . "\n";
echo "Attributes class: " . get_class($registry->attributes) . "\n";
// Check if we can iterate
if (method_exists($registry->attributes, 'getAllTypes')) {
echo "\n=== Available Attribute Types ===\n";
$allAttributes = $registry->attributes->getAllTypes();
foreach ($allAttributes as $attrClass) {
$count = count($registry->attributes->get($attrClass));
echo "- $attrClass: $count items\n";
}
} else {
echo "Method getAllTypes not available\n";
}
} else {
echo "✅ Found initializers:\n";
foreach ($initializers as $mapping) {
$className = $mapping->class->getFullyQualified();
$methodName = $mapping->method ? $mapping->method->toString() : '(class-level)';
echo "- {$className}::{$methodName}\n";
echo " File: " . $mapping->file->toString() . "\n";
echo " Target: " . $mapping->target . "\n";
echo "\n";
}
}
} else {
echo "❌ AttributeRegistry doesn't have 'get' method\n";
}
} catch (Exception $e) {
echo "❌ Error: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}