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:
114
tests/debug/test-factory-vs-direct-discovery.php
Normal file
114
tests/debug/test-factory-vs-direct-discovery.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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\DI\InitializerMapper;
|
||||
use App\Framework\Discovery\Factory\DiscoveryServiceFactory;
|
||||
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 "=== Comparing Factory vs Direct Discovery ===\n\n";
|
||||
|
||||
try {
|
||||
$projectRoot = dirname(__DIR__, 2);
|
||||
$srcPath = $projectRoot . '/src';
|
||||
|
||||
$container = new DefaultContainer();
|
||||
$pathProvider = new PathProvider($projectRoot);
|
||||
$clock = new SystemClock();
|
||||
$cacheDriver = new InMemoryCache();
|
||||
$serializer = new JsonSerializer();
|
||||
$cache = new GeneralCache($cacheDriver, $serializer);
|
||||
|
||||
echo "=== Method 1: Using DiscoveryServiceFactory ===\n";
|
||||
$factory = new DiscoveryServiceFactory($container, $pathProvider, $cache, $clock);
|
||||
$discoveryService1 = $factory->createForDevelopment([$srcPath]);
|
||||
|
||||
$registry1 = $discoveryService1->discover();
|
||||
$initializers1 = $registry1->attributes->get(Initializer::class);
|
||||
|
||||
echo "Factory-based discovery:\n";
|
||||
echo "- Total items: " . count($registry1) . "\n";
|
||||
echo "- Initializers: " . count($initializers1) . "\n";
|
||||
echo "- Attribute types: " . count($registry1->attributes->getAllTypes()) . "\n\n";
|
||||
|
||||
echo "=== Method 2: Direct UnifiedDiscoveryService ===\n";
|
||||
$fileSystemService = new FileSystemService();
|
||||
$reflectionProvider = new CachedReflectionProvider();
|
||||
|
||||
$config = new DiscoveryConfiguration(
|
||||
paths: [$srcPath],
|
||||
attributeMappers: [new InitializerMapper()],
|
||||
targetInterfaces: [],
|
||||
useCache: false
|
||||
);
|
||||
|
||||
$discoveryService2 = new UnifiedDiscoveryService(
|
||||
pathProvider: $pathProvider,
|
||||
cache: $cache,
|
||||
clock: $clock,
|
||||
reflectionProvider: $reflectionProvider,
|
||||
configuration: $config,
|
||||
attributeMappers: [new InitializerMapper()],
|
||||
targetInterfaces: []
|
||||
);
|
||||
|
||||
$registry2 = $discoveryService2->discover();
|
||||
$initializers2 = $registry2->attributes->get(Initializer::class);
|
||||
|
||||
echo "Direct discovery:\n";
|
||||
echo "- Total items: " . count($registry2) . "\n";
|
||||
echo "- Initializers: " . count($initializers2) . "\n";
|
||||
echo "- Attribute types: " . count($registry2->attributes->getAllTypes()) . "\n\n";
|
||||
|
||||
echo "=== Detailed Comparison ===\n";
|
||||
echo "Factory found " . count($initializers1) . " initializers:\n";
|
||||
foreach ($initializers1 as $mapping) {
|
||||
$className = $mapping->class->getShortName();
|
||||
$methodName = $mapping->method ? $mapping->method->toString() : '(class)';
|
||||
echo "- $className::$methodName\n";
|
||||
}
|
||||
|
||||
echo "\nDirect found " . count($initializers2) . " initializers:\n";
|
||||
foreach ($initializers2 as $mapping) {
|
||||
$className = $mapping->class->getShortName();
|
||||
$methodName = $mapping->method ? $mapping->method->toString() : '(class)';
|
||||
echo "- $className::$methodName\n";
|
||||
}
|
||||
|
||||
// Check configuration differences
|
||||
echo "\n=== Configuration Analysis ===\n";
|
||||
|
||||
// Get factory configuration somehow
|
||||
echo "Factory configuration: Using multiple mappers from buildAttributeMappers()\n";
|
||||
echo "Direct configuration: Only InitializerMapper\n";
|
||||
|
||||
echo "\nFactory attribute types found:\n";
|
||||
foreach ($registry1->attributes->getAllTypes() as $type) {
|
||||
$shortType = substr(strrchr($type, '\\'), 1) ?: $type;
|
||||
$count = $registry1->attributes->getCount($type);
|
||||
echo "- $shortType: $count items\n";
|
||||
}
|
||||
|
||||
echo "\nDirect attribute types found:\n";
|
||||
foreach ($registry2->attributes->getAllTypes() as $type) {
|
||||
$shortType = substr(strrchr($type, '\\'), 1) ?: $type;
|
||||
$count = $registry2->attributes->getCount($type);
|
||||
echo "- $shortType: $count items\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ Error: " . $e->getMessage() . "\n";
|
||||
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user