Files
michaelschiemer/tests/debug/test-foreach-with-data.php
Michael Schiemer c8b47e647d feat(Docker): Upgrade to PHP 8.5.0RC3 with native ext-uri support
BREAKING CHANGE: Requires PHP 8.5.0RC3

Changes:
- Update Docker base image from php:8.4-fpm to php:8.5.0RC3-fpm
- Enable ext-uri for native WHATWG URL parsing support
- Update composer.json PHP requirement from ^8.4 to ^8.5
- Add ext-uri as required extension in composer.json
- Move URL classes from Url.php85/ to Url/ directory (now compatible)
- Remove temporary PHP 8.4 compatibility workarounds

Benefits:
- Native URL parsing with Uri\WhatWg\Url class
- Better performance for URL operations
- Future-proof with latest PHP features
- Eliminates PHP version compatibility issues
2025-10-27 09:31:28 +01:00

99 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\DI\DefaultContainer;
use App\Framework\View\Processors\ForStringProcessor;
use App\Framework\View\RenderContext;
use App\Framework\Meta\MetaData;
// Initialize container
$container = new DefaultContainer();
// Create ForStringProcessor
$forStringProcessor = $container->get(ForStringProcessor::class);
// Test HTML with foreach attribute - EXACTLY like in ML Dashboard
$html = <<<'HTML'
<table class="admin-table">
<thead>
<tr>
<th>Model Name</th>
<th>Version</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr foreach="$models as $model">
<td>{{ $model['model_name'] }}</td>
<td>{{ $model['version'] }}</td>
<td>{{ $model['status'] }}</td>
</tr>
</tbody>
</table>
HTML;
// Test data with 2 models
$data = [
'models' => [
[
'model_name' => 'fraud-detector',
'version' => '1.0.0',
'status' => 'healthy'
],
[
'model_name' => 'spam-classifier',
'version' => '2.0.0',
'status' => 'degraded'
],
]
];
// Create render context
$context = new RenderContext(
template: 'test',
metaData: new MetaData('test', 'test'),
data: $data,
controllerClass: null
);
echo "=== ORIGINAL HTML ===\n";
echo $html . "\n\n";
echo "=== PROCESSING WITH ForStringProcessor ===\n";
$result = $forStringProcessor->process($html, $context);
echo "=== PROCESSED HTML ===\n";
echo $result . "\n\n";
echo "=== VERIFICATION ===\n";
if (str_contains($result, 'foreach=')) {
echo "❌ PROBLEM: foreach attribute still present\n";
} else {
echo "✅ Good: foreach attribute removed\n";
}
if (str_contains($result, '{{ $model')) {
echo "❌ PROBLEM: Placeholders not replaced\n";
} else {
echo "✅ Good: Placeholders replaced\n";
}
if (str_contains($result, 'fraud-detector')) {
echo "✅ Good: Model data found in output\n";
} else {
echo "❌ PROBLEM: Model data NOT found in output\n";
}
if (str_contains($result, 'spam-classifier')) {
echo "✅ Good: Second model data found in output\n";
} else {
echo "❌ PROBLEM: Second model data NOT found in output\n";
}
// Count rows
$rowCount = substr_count($result, '<tr>');
echo "\nGenerated $rowCount <tr> elements (expected: 3 - 1 header + 2 data rows)\n";