- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
179 lines
5.1 KiB
PHP
179 lines
5.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Test SSE Channel Rendering
|
|
*
|
|
* Verifies that Components with getSseChannel() method automatically render
|
|
* the data-sse-channel attribute for JavaScript SSE integration.
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Application\LiveComponents\LivePresence\LivePresenceComponent;
|
|
use App\Application\LiveComponents\NotificationCenter\NotificationCenterComponent;
|
|
use App\Framework\DI\DefaultContainer;
|
|
use App\Framework\Http\Session\InMemorySession;
|
|
use App\Framework\LiveComponents\ComponentRegistry;
|
|
use App\Framework\LiveComponents\ValueObjects\ComponentId;
|
|
use App\Framework\View\LiveComponentRenderer;
|
|
use App\Framework\View\TemplateRenderer;
|
|
use App\Framework\View\TemplateRendererInitializer;
|
|
|
|
// Create minimal dependencies
|
|
$container = new DefaultContainer();
|
|
|
|
// Create TemplateRenderer (needed by LiveComponentRenderer)
|
|
$templateRendererInit = new TemplateRendererInitializer();
|
|
$templateRenderer = $templateRendererInit->init($container);
|
|
|
|
// Create Session (needed for CSRF tokens)
|
|
$session = new InMemorySession();
|
|
|
|
// Create LiveComponentRenderer
|
|
$liveComponentRenderer = new LiveComponentRenderer($templateRenderer, $session);
|
|
|
|
// Create ComponentRegistry
|
|
$registry = new ComponentRegistry($liveComponentRenderer);
|
|
|
|
echo "=== SSE Channel Rendering Test ===\n\n";
|
|
|
|
// Test 1: NotificationCenter Component
|
|
echo "Test 1: NotificationCenter Component\n";
|
|
echo "-------------------------------------\n";
|
|
|
|
$notificationComponent = new NotificationCenterComponent(
|
|
id: new ComponentId('notification-center', 'user-123'),
|
|
initialData: null,
|
|
notifications: [
|
|
[
|
|
'id' => 'notif-1',
|
|
'title' => 'Test Notification',
|
|
'message' => 'This is a test',
|
|
'type' => 'info',
|
|
'read' => false,
|
|
'timestamp' => time(),
|
|
],
|
|
],
|
|
unreadCount: 1,
|
|
filter: 'all',
|
|
showPanel: false
|
|
);
|
|
|
|
// Get SSE channel
|
|
$sseChannel = $notificationComponent->getSseChannel();
|
|
echo "SSE Channel: {$sseChannel}\n";
|
|
|
|
// Render with wrapper
|
|
$html = $registry->renderWithWrapper($notificationComponent);
|
|
|
|
// Check if data-sse-channel is present
|
|
if (str_contains($html, 'data-sse-channel=')) {
|
|
echo "✅ SUCCESS: data-sse-channel attribute found\n";
|
|
|
|
// Extract the channel value
|
|
if (preg_match('/data-sse-channel="([^"]+)"/', $html, $matches)) {
|
|
$renderedChannel = $matches[1];
|
|
echo " Rendered channel: {$renderedChannel}\n";
|
|
|
|
if ($renderedChannel === $sseChannel) {
|
|
echo "✅ Channel matches getSseChannel() return value\n";
|
|
} else {
|
|
echo "❌ FAIL: Channel mismatch! Expected: {$sseChannel}, Got: {$renderedChannel}\n";
|
|
}
|
|
}
|
|
} else {
|
|
echo "❌ FAIL: data-sse-channel attribute NOT found\n";
|
|
echo "HTML preview:\n";
|
|
echo substr($html, 0, 300) . "...\n";
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
// Test 2: LivePresence Component
|
|
echo "Test 2: LivePresence Component\n";
|
|
echo "-------------------------------------\n";
|
|
|
|
$presenceComponent = new LivePresenceComponent(
|
|
id: new ComponentId('live-presence', 'room-lobby'),
|
|
initialData: null,
|
|
users: [
|
|
[
|
|
'user_id' => 'user-1',
|
|
'user_name' => 'John Doe',
|
|
'avatar_url' => '',
|
|
'status' => 'online',
|
|
'joined_at' => time() - 300,
|
|
'last_seen' => time(),
|
|
],
|
|
],
|
|
showAvatars: true,
|
|
showNames: true,
|
|
showCount: true,
|
|
maxVisibleUsers: 10,
|
|
presenceTimeout: 300,
|
|
allowAnonymous: false
|
|
);
|
|
|
|
// Get SSE channel
|
|
$sseChannel = $presenceComponent->getSseChannel();
|
|
echo "SSE Channel: {$sseChannel}\n";
|
|
|
|
// Render with wrapper
|
|
$html = $registry->renderWithWrapper($presenceComponent);
|
|
|
|
// Check if data-sse-channel is present
|
|
if (str_contains($html, 'data-sse-channel=')) {
|
|
echo "✅ SUCCESS: data-sse-channel attribute found\n";
|
|
|
|
// Extract the channel value
|
|
if (preg_match('/data-sse-channel="([^"]+)"/', $html, $matches)) {
|
|
$renderedChannel = $matches[1];
|
|
echo " Rendered channel: {$renderedChannel}\n";
|
|
|
|
if ($renderedChannel === $sseChannel) {
|
|
echo "✅ Channel matches getSseChannel() return value\n";
|
|
} else {
|
|
echo "❌ FAIL: Channel mismatch! Expected: {$sseChannel}, Got: {$renderedChannel}\n";
|
|
}
|
|
}
|
|
} else {
|
|
echo "❌ FAIL: data-sse-channel attribute NOT found\n";
|
|
echo "HTML preview:\n";
|
|
echo substr($html, 0, 300) . "...\n";
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
// Test 3: Verify HTML structure
|
|
echo "Test 3: Verify Complete HTML Structure\n";
|
|
echo "-------------------------------------\n";
|
|
|
|
$html = $registry->renderWithWrapper($notificationComponent);
|
|
|
|
$requiredAttributes = [
|
|
'data-live-component',
|
|
'data-state',
|
|
'data-csrf-token',
|
|
'data-sse-channel',
|
|
];
|
|
|
|
$allPresent = true;
|
|
foreach ($requiredAttributes as $attr) {
|
|
if (str_contains($html, $attr . '=')) {
|
|
echo "✅ {$attr} present\n";
|
|
} else {
|
|
echo "❌ {$attr} MISSING\n";
|
|
$allPresent = false;
|
|
}
|
|
}
|
|
|
|
if ($allPresent) {
|
|
echo "\n✅ ALL TESTS PASSED - SSE Channel Rendering works!\n";
|
|
} else {
|
|
echo "\n❌ SOME TESTS FAILED - Check implementation\n";
|
|
}
|
|
|
|
echo "\n=== Test Complete ===\n";
|