'); if ($selfClose !== false) { $tag = substr($rest, 0, $selfClose + 2); } else { $close = strpos($rest, '>'); $tag = $close === false ? $rest : substr($rest, 0, $close + 1); } if (preg_match('/maxlength="(\d+)"/', $tag, $m)) { $htmlMax = (int)$m[1]; } break; } if (!$foundLine) { echo "FAIL $label: no line containing $needle\n"; $failures++; continue; } $schemaSize = null; if (!is_file($schemaPath)) { echo "FAIL $label: missing schema $schemaPath\n"; $failures++; continue; } $schemaText = file_get_contents($schemaPath); if ($table !== null) { $start = strpos($schemaText, 'CREATE TABLE `' . $table . '`'); if ($start !== false) { $end = strpos($schemaText, ');', $start); if ($end === false) { $end = strpos($schemaText, ';', $start); } $schemaText = $end === false ? substr($schemaText, $start) : substr($schemaText, $start, $end - $start + 1); } } if (preg_match('/`' . $column . '`\s+varchar\((\d+)\)/', $schemaText, $m)) { $schemaSize = (int)$m[1]; } if ($htmlMax === null) { echo "FAIL $label: no maxlength attribute (expected $expected)\n"; $failures++; continue; } if ($htmlMax !== $expected) { echo "FAIL $label: maxlength=$htmlMax expected $expected\n"; $failures++; continue; } if ($schemaSize === null) { echo "FAIL $label: schema column $column not found in $schemaFile\n"; $failures++; continue; } if ($schemaSize !== $expected) { echo "FAIL $label: schema varchar($schemaSize) expected $expected\n"; $failures++; continue; } echo "ok $label maxlength=$htmlMax schema=varchar($schemaSize)\n"; } $total = count($cases); if ($failures > 0) { echo "SUMMARY: " . ($total - $failures) . "/$total passed, $failures failed\n"; exit(1); } echo "SUMMARY: $total/$total passed\n"; exit(0);