Files
michaelschiemer/tests/debug/test-request-binding.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

120 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Core\AppBootstrapper;
use App\Framework\Core\Application;
use App\Framework\Http\HttpRequest;
use App\Framework\Http\Request;
echo "=== Testing Request Binding in Container ===\n\n";
try {
// Bootstrap the application
$basePath = dirname(__DIR__, 2);
// Create dependencies for AppBootstrapper
$clock = new \App\Framework\DateTime\SystemClock();
$highResClock = new \App\Framework\DateTime\SystemHighResolutionClock();
$memoryMonitor = new \App\Framework\Performance\MemoryMonitor();
$performanceCollector = new \App\Framework\Performance\EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, false);
$bootstrapper = new AppBootstrapper($basePath, $performanceCollector, $memoryMonitor);
$application = $bootstrapper->bootstrapWeb();
$container = $application->getContainer();
echo "1. Checking if Request interface is bound:\n";
$requestBound = false;
try {
$request = $container->get(Request::class);
echo " ✅ Request is bound in container\n";
echo " Type: " . get_class($request) . "\n";
$requestBound = true;
} catch (Exception $e) {
echo " ❌ Request NOT bound: " . $e->getMessage() . "\n";
}
echo "\n2. Checking if HttpRequest is bound:\n";
try {
$httpRequest = $container->get(HttpRequest::class);
echo " ✅ HttpRequest is bound in container\n";
echo " Type: " . get_class($httpRequest) . "\n";
} catch (Exception $e) {
echo " ❌ HttpRequest NOT bound: " . $e->getMessage() . "\n";
}
echo "\n3. Checking container bindings:\n";
// Use reflection to check bindings
$reflection = new ReflectionClass($container);
$bindingsProperty = $reflection->getProperty('bindings');
$bindingsProperty->setAccessible(true);
$bindings = $bindingsProperty->getValue($container);
echo " Total bindings: " . count($bindings) . "\n";
// Check for Request-related bindings
$requestRelated = [];
foreach ($bindings as $key => $binding) {
if (stripos($key, 'request') !== false) {
$requestRelated[$key] = $binding;
}
}
echo " Request-related bindings:\n";
if (empty($requestRelated)) {
echo " ❌ No Request-related bindings found!\n";
} else {
foreach ($requestRelated as $key => $binding) {
$shortKey = substr($key, strrpos($key, '\\') + 1);
echo " - $shortKey\n";
}
}
// Check lazy services
echo "\n4. Checking lazy services:\n";
$lazyServicesProperty = $reflection->getProperty('lazyServices');
$lazyServicesProperty->setAccessible(true);
$lazyServices = $lazyServicesProperty->getValue($container);
echo " Total lazy services: " . count($lazyServices) . "\n";
$requestLazy = [];
foreach ($lazyServices as $key => $factory) {
if (stripos($key, 'request') !== false) {
$requestLazy[$key] = $factory;
}
}
echo " Request-related lazy services:\n";
if (empty($requestLazy)) {
echo " ❌ No Request-related lazy services found!\n";
} else {
foreach ($requestLazy as $key => $factory) {
$shortKey = substr($key, strrpos($key, '\\') + 1);
echo " - $shortKey\n";
}
}
echo "\n5. Testing RequestFactory directly:\n";
try {
$factory = $container->get(\App\Framework\Http\RequestFactory::class);
echo " ✅ RequestFactory found in container\n";
// Try to create request
$request = $factory->createFromGlobals();
echo " ✅ Request created: " . get_class($request) . "\n";
} catch (Exception $e) {
echo " ❌ RequestFactory error: " . $e->getMessage() . "\n";
}
} catch (Exception $e) {
echo "❌ Error: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}