Counter';
}
public function renderWithWrapper(LiveComponentContract $component): string
{
echo "✓ renderWithWrapper() WAS CALLED\n";
return '
Counter HTML
';
}
public function isRegistered(string $componentName): bool
{
return $componentName === 'counter';
}
public function getClassName(string $componentName): ?string
{
return $componentName === 'counter' ? 'TestCounterComponent' : null;
}
public function getAllComponentNames(): array
{
return ['counter'];
}
};
$htmlComponentRegistry = new class implements HtmlComponentRegistryInterface {
public function has(string $componentName): bool
{
return false;
}
public function render(string $componentName, string $content, array $attributes): string
{
return '';
}
public function getAllComponentNames(): array
{
return [];
}
};
// This metadata says the component ONLY has 'initialValue' property
$metadataCache = new class implements ComponentMetadataCacheInterface {
public function get(string $className): CompiledComponentMetadata
{
return new CompiledComponentMetadata(
className: 'TestCounterComponent',
componentName: 'counter',
properties: [
'initialValue' => new ComponentPropertyMetadata(
name: 'initialValue',
type: 'int',
isPublic: true,
isReadonly: false
)
],
actions: [],
constructorParams: []
);
}
public function has(string $className): bool
{
return true;
}
public function invalidate(string $className): bool
{
return true;
}
public function warmCache(array $classNames): int
{
return 0;
}
};
$processor = new XComponentProcessor(
$liveComponentRegistry,
$htmlComponentRegistry,
$metadataCache,
new DomComponentService()
);
$parser = new DomTemplateParser();
// Test 1: HTML with id attribute (should be accepted, 'id' is skipped in validation)
echo "=== Test 1: With 'id' attribute (should work) ===\n";
$html1 = '';
$dom1 = $parser->parseToWrapper($html1);
$context = new RenderContext(
template: 'test',
metaData: new MetaData('test'),
data: []
);
$result1 = $processor->process($dom1, $context);
$resultHtml1 = $result1->document->saveHTML();
echo "Result HTML: {$resultHtml1}\n";
if (str_contains($resultHtml1, 'data-component-id')) {
echo "✅ SUCCESS\n";
} else {
echo "❌ FAILURE\n";
if (str_contains($resultHtml1, 'XComponentProcessor Error')) {
echo "Error message found in HTML\n";
}
}
echo "\n";
// Test 2: HTML WITHOUT id attribute (should generate auto-id)
echo "=== Test 2: Without 'id' attribute (should work) ===\n";
$html2 = '';
$dom2 = $parser->parseToWrapper($html2);
$result2 = $processor->process($dom2, $context);
$resultHtml2 = $result2->document->saveHTML();
echo "Result HTML: {$resultHtml2}\n";
if (str_contains($resultHtml2, 'data-component-id')) {
echo "✅ SUCCESS\n";
} else {
echo "❌ FAILURE\n";
if (str_contains($resultHtml2, 'XComponentProcessor Error')) {
echo "Error message found in HTML\n";
}
}