feat: CI/CD pipeline setup complete - Ansible playbooks updated, secrets configured, workflow ready
This commit is contained in:
114
tests/debug/test-shutdown-handling.php
Normal file
114
tests/debug/test-shutdown-handling.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Debug Script: Test Shutdown Handling with Fatal Errors
|
||||
*
|
||||
* This script tests the ShutdownHandlerManager implementation by:
|
||||
* 1. Triggering various fatal errors
|
||||
* 2. Verifying shutdown handlers execute
|
||||
* 3. Confirming OWASP security logging
|
||||
* 4. Testing event dispatch
|
||||
*
|
||||
* Usage: php tests/debug/test-shutdown-handling.php [test-type]
|
||||
* Test Types:
|
||||
* - fatal: Trigger E_ERROR (undefined function)
|
||||
* - parse: Trigger E_PARSE (syntax error via eval)
|
||||
* - memory: Trigger memory exhaustion
|
||||
* - normal: Normal shutdown (no error)
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use App\Framework\Core\AppBootstrapper;
|
||||
use App\Framework\DateTime\SystemClock;
|
||||
use App\Framework\DateTime\SystemHighResolutionClock;
|
||||
use App\Framework\Performance\EnhancedPerformanceCollector;
|
||||
use App\Framework\Performance\MemoryMonitor;
|
||||
use App\Framework\Shutdown\ShutdownHandlerManager;
|
||||
use App\Framework\DI\Container;
|
||||
|
||||
// Bootstrap application
|
||||
$basePath = dirname(__DIR__, 2);
|
||||
$clock = new SystemClock();
|
||||
$highResClock = new SystemHighResolutionClock();
|
||||
$memoryMonitor = new MemoryMonitor();
|
||||
$collector = new EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, enabled: false);
|
||||
|
||||
$bootstrapper = new AppBootstrapper($basePath, $collector, $memoryMonitor);
|
||||
$container = $bootstrapper->bootstrapWorker();
|
||||
|
||||
// Get ShutdownHandlerManager from container
|
||||
$shutdownManager = $container->get(ShutdownHandlerManager::class);
|
||||
|
||||
// Register test handler to verify execution
|
||||
$shutdownManager->registerHandler(function ($event) {
|
||||
echo "\n[TEST HANDLER] Shutdown handler executed!\n";
|
||||
echo " - Fatal Error: " . ($event->isFatalError() ? 'YES' : 'NO') . "\n";
|
||||
echo " - Memory Usage: " . $event->memoryUsage->toHumanReadable() . "\n";
|
||||
echo " - Peak Memory: " . $event->peakMemoryUsage->toHumanReadable() . "\n";
|
||||
|
||||
if ($event->isFatalError()) {
|
||||
echo " - Error Type: " . $event->getErrorTypeName() . "\n";
|
||||
echo " - Error Message: " . $event->getErrorMessage() . "\n";
|
||||
echo " - Error File: " . $event->getErrorFile() . "\n";
|
||||
echo " - Error Line: " . $event->getErrorLine() . "\n";
|
||||
}
|
||||
|
||||
echo "[TEST HANDLER] Completed successfully\n\n";
|
||||
}, priority: 100);
|
||||
|
||||
// Determine test type from CLI argument
|
||||
$testType = $argv[1] ?? 'fatal';
|
||||
|
||||
echo "\n========================================\n";
|
||||
echo "Shutdown Handling Test: " . strtoupper($testType) . "\n";
|
||||
echo "========================================\n\n";
|
||||
|
||||
echo "Application bootstrapped successfully.\n";
|
||||
echo "ShutdownHandlerManager registered.\n";
|
||||
echo "Test handler added with priority 100.\n\n";
|
||||
|
||||
echo "Triggering test scenario in 2 seconds...\n";
|
||||
sleep(2);
|
||||
|
||||
switch ($testType) {
|
||||
case 'fatal':
|
||||
echo "\n[TEST] Triggering E_ERROR via undefined function call...\n\n";
|
||||
// This will trigger E_ERROR: Call to undefined function
|
||||
undefinedFunction();
|
||||
break;
|
||||
|
||||
case 'parse':
|
||||
echo "\n[TEST] Triggering E_PARSE via eval syntax error...\n\n";
|
||||
// This will trigger E_PARSE
|
||||
eval('this is invalid php syntax');
|
||||
break;
|
||||
|
||||
case 'memory':
|
||||
echo "\n[TEST] Triggering memory exhaustion...\n\n";
|
||||
ini_set('memory_limit', '10M');
|
||||
$data = [];
|
||||
while (true) {
|
||||
// Allocate memory until exhaustion
|
||||
$data[] = str_repeat('x', 1024 * 1024); // 1MB chunks
|
||||
}
|
||||
break;
|
||||
|
||||
case 'normal':
|
||||
echo "\n[TEST] Normal shutdown (no error)...\n\n";
|
||||
echo "Application will exit normally.\n";
|
||||
echo "Shutdown handlers should still execute.\n\n";
|
||||
// Normal exit
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
echo "\nUnknown test type: {$testType}\n";
|
||||
echo "Valid types: fatal, parse, memory, normal\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// This code should never be reached for fatal errors
|
||||
echo "\n[UNEXPECTED] Code execution continued after fatal error!\n";
|
||||
echo "This should NOT happen.\n\n";
|
||||
Reference in New Issue
Block a user