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
This commit is contained in:
116
tests/debug/test-discovery-registry-completeness.php
Normal file
116
tests/debug/test-discovery-registry-completeness.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?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\Initializer;
|
||||
use App\Framework\Discovery\Factory\DiscoveryServiceFactory;
|
||||
use App\Framework\Serializer\Json\JsonSerializer;
|
||||
|
||||
echo "=== Testing DiscoveryRegistry Completeness ===\n\n";
|
||||
|
||||
try {
|
||||
// Setup
|
||||
$projectRoot = dirname(__DIR__, 2);
|
||||
$srcPath = $projectRoot . '/src';
|
||||
|
||||
echo "Project root: $projectRoot\n";
|
||||
echo "Source path: $srcPath\n\n";
|
||||
|
||||
$container = new DefaultContainer();
|
||||
$pathProvider = new PathProvider($projectRoot);
|
||||
$clock = new SystemClock();
|
||||
|
||||
// Create cache for discovery
|
||||
$cacheDriver = new InMemoryCache();
|
||||
$serializer = new JsonSerializer();
|
||||
$cache = new GeneralCache($cacheDriver, $serializer);
|
||||
|
||||
// Use DiscoveryServiceFactory like in production
|
||||
$factory = new DiscoveryServiceFactory($container, $pathProvider, $cache, $clock);
|
||||
$discoveryService = $factory->createForDevelopment([$srcPath]);
|
||||
|
||||
echo "Starting full discovery scan using DiscoveryServiceFactory...\n";
|
||||
$registry = $discoveryService->discover();
|
||||
echo "Discovery completed!\n\n";
|
||||
|
||||
// Analyze registry completeness
|
||||
echo "=== Registry Analysis ===\n";
|
||||
echo "Total items in registry: " . count($registry) . "\n";
|
||||
echo "Is empty: " . ($registry->isEmpty() ? 'Yes' : 'No') . "\n\n";
|
||||
|
||||
// Check individual registries
|
||||
echo "=== Individual Registry Stats ===\n";
|
||||
echo "Attributes: " . count($registry->attributes) . " items\n";
|
||||
echo "Interfaces: " . count($registry->interfaces) . " items\n";
|
||||
echo "Routes: " . count($registry->routes) . " items\n";
|
||||
echo "Templates: " . count($registry->templates) . " items\n\n";
|
||||
|
||||
// Check specific attribute types
|
||||
echo "=== Attribute Type Analysis ===\n";
|
||||
$attributeTypes = $registry->attributes->getAllTypes();
|
||||
echo "Total attribute types found: " . count($attributeTypes) . "\n\n";
|
||||
|
||||
foreach ($attributeTypes as $type) {
|
||||
$count = $registry->attributes->getCount($type);
|
||||
$shortType = substr(strrchr($type, '\\'), 1) ?: $type;
|
||||
echo "- $shortType: $count items\n";
|
||||
}
|
||||
|
||||
// Focus on Initializer specifically
|
||||
echo "\n=== Initializer Analysis ===\n";
|
||||
$initializerClass = Initializer::class;
|
||||
$initializerMappings = $registry->attributes->get($initializerClass);
|
||||
|
||||
echo "Initializer attribute class: $initializerClass\n";
|
||||
echo "Found initializers: " . count($initializerMappings) . "\n\n";
|
||||
|
||||
if (empty($initializerMappings)) {
|
||||
echo "❌ No initializers found! Checking alternative lookups...\n";
|
||||
|
||||
// Try different class name formats
|
||||
$alternativeNames = [
|
||||
'App\\Framework\\DI\\Initializer',
|
||||
'App\\\\Framework\\\\DI\\\\Initializer',
|
||||
'\\App\\Framework\\DI\\Initializer',
|
||||
];
|
||||
|
||||
foreach ($alternativeNames as $altName) {
|
||||
$altMappings = $registry->attributes->get($altName);
|
||||
echo "- $altName: " . count($altMappings) . " items\n";
|
||||
}
|
||||
|
||||
echo "\nAll available attribute types:\n";
|
||||
foreach ($attributeTypes as $type) {
|
||||
echo "- $type\n";
|
||||
}
|
||||
} else {
|
||||
echo "✅ Initializers found! Showing first 5:\n";
|
||||
for ($i = 0; $i < min(5, count($initializerMappings)); $i++) {
|
||||
$mapping = $initializerMappings[$i];
|
||||
$className = $mapping->class->getShortName();
|
||||
$methodName = $mapping->method ? $mapping->method->toString() : '(class-level)';
|
||||
echo "- $className::$methodName\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Memory stats
|
||||
echo "\n=== Memory Statistics ===\n";
|
||||
$memStats = $registry->getMemoryStats();
|
||||
echo "Total estimated memory: " . number_format($memStats['total_estimated_bytes']) . " bytes\n";
|
||||
echo "Attributes memory: " . $memStats['attributes']['memory_footprint'] . "\n";
|
||||
|
||||
// Check if registry got optimized
|
||||
$registry->optimize();
|
||||
echo "\n✅ Registry analysis completed!\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ Error: " . $e->getMessage() . "\n";
|
||||
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user