singleton(\App\Framework\Cache\Cache::class, $cache); $container->singleton(\App\Framework\DateTime\Clock::class, $clock); $container->singleton(PathProvider::class, $pathProvider); $reflectionProvider = new CachedReflectionProvider(); // Force create a cli-script execution context instead of auto-detecting $forcedContext = new ExecutionContext(ContextType::CLI_SCRIPT, ['script' => __FILE__]); $container->singleton(\App\Framework\Reflection\ReflectionProvider::class, $reflectionProvider); $container->singleton(ExecutionContext::class, $forcedContext); $container->singleton(InitializerProcessor::class, fn ($c) => new InitializerProcessor( $c, $c->get(\App\Framework\Reflection\ReflectionProvider::class), $c->get(ExecutionContext::class) )); // App config for testing - same as working console $appConfig = new AppConfig( environment: 'development', // Use development like console.php would debug: true, timezone: Timezone::UTC, locale: 'en' ); $container->singleton(AppConfig::class, $appConfig); $cache->clear(); echo "1. Environment Setup:\n"; echo " - Forced Context: " . $forcedContext->getType()->value . "\n"; echo " - App Environment: development\n"; echo " - Source Path: " . $pathProvider->getSourcePath() . "\n\n"; echo "2. Discovery Test with Forced CLI Context:\n"; try { $bootstrapper = new DiscoveryServiceBootstrapper($container, $clock); echo " - Bootstrapper created\n"; $registry = $bootstrapper->performBootstrap($pathProvider, $cache, null); echo " - Discovery completed\n"; echo " - Registry empty: " . ($registry->isEmpty() ? 'YES' : 'NO') . "\n"; echo " - Total attribute types: " . count($registry->attributes->getAllTypes()) . "\n"; $consoleCommands = $registry->attributes->get(ConsoleCommand::class); echo " - ConsoleCommand attributes found: " . count($consoleCommands) . "\n"; if (count($consoleCommands) > 0) { echo " - ✓ SUCCESS! Discovery is working with CLI context\n"; echo " - Sample commands:\n"; $sampleCount = 0; foreach ($consoleCommands as $discovered) { if ($sampleCount >= 5) { break; } $command = $discovered->createAttributeInstance(); echo " * " . $command->name . " - " . $command->description . "\n"; $sampleCount++; } } else { echo " - Still no commands found. All types:\n"; foreach ($registry->attributes->getAllTypes() as $type) { $count = $registry->attributes->getCount($type); echo " * $type: $count instances\n"; } } } catch (\Throwable $e) { echo " - ❌ Error: " . $e->getMessage() . "\n"; echo " - File: " . $e->getFile() . ":" . $e->getLine() . "\n"; echo " - Stack trace:\n" . $e->getTraceAsString() . "\n"; } echo "\n=== End Test ===\n";