From 81c8b5b2d80b0e4afc462817ac3d9a9a84b692da Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 24 Mar 2026 23:20:28 +0100 Subject: [PATCH 1/2] Relocate `TestCase` to the `ipl\Html\Test` namespace The class was only reachable via `autoload-dev`, so downstream packages had no way to extend or use it in their own test suites. Moving it to `ipl\Html\Test` exposes it through the library's existing autoload entry, allowing consumers to rely on it without adjusting their `composer.json`. --- {tests => src/Test}/TestCase.php | 2 +- tests/AttributeTest.php | 1 + tests/AttributesTest.php | 1 + tests/BaseHtmlElementTest.php | 1 + tests/DeferredTextTest.php | 1 + tests/DocumentationFormsTest.php | 1 + tests/DocumentationQuickStartTest.php | 1 + tests/DocumentationTablesTest.php | 1 + tests/FormDecorator/DecorationResultsTest.php | 2 +- tests/FormDecorator/DecoratorChainTest.php | 2 +- tests/FormDecorator/DescriptionDecoratorTest.php | 2 +- tests/FormDecorator/ErrorsDecoratorTest.php | 2 +- tests/FormDecorator/FieldsetDecoratorTest.php | 2 +- tests/FormDecorator/FormDecorationResultTest.php | 2 +- tests/FormDecorator/FormDecorationTest.php | 2 +- tests/FormDecorator/FormElementDecorationTest.php | 2 +- tests/FormDecorator/HtmlTagDecoratorTest.php | 2 +- tests/FormDecorator/LabelDecoratorTest.php | 2 +- tests/FormElement/CheckboxElementTest.php | 1 + tests/FormElement/FieldsetElementTest.php | 2 +- tests/FormElement/FileElementTest.php | 2 +- tests/FormElement/FormElementValidationTest.php | 2 +- tests/FormElement/LocalDateTimeElementTest.php | 1 + tests/FormElement/RadioElementTest.php | 2 +- tests/FormElement/SelectElementTest.php | 2 +- tests/FormElement/SelectOptionTest.php | 2 +- tests/FormElement/SubmitButtonElementTest.php | 2 +- tests/FormElement/TextElementTest.php | 2 +- tests/FormElementDecoratorTest.php | 1 + tests/FormElementsTest.php | 1 + tests/FormTest.php | 1 + tests/FormattedStringTest.php | 1 + tests/HtmlDocumentTest.php | 1 + tests/HtmlStringTest.php | 1 + tests/HtmlTest.php | 1 + tests/TemplateStringTest.php | 3 ++- 36 files changed, 37 insertions(+), 20 deletions(-) rename {tests => src/Test}/TestCase.php (98%) diff --git a/tests/TestCase.php b/src/Test/TestCase.php similarity index 98% rename from tests/TestCase.php rename to src/Test/TestCase.php index 22dfe954..7076fad7 100644 --- a/tests/TestCase.php +++ b/src/Test/TestCase.php @@ -1,6 +1,6 @@ Date: Tue, 24 Mar 2026 23:33:49 +0100 Subject: [PATCH 2/2] Clean up `TestCase` for PHP 8.2 and modern PHPUnit Drop the pre-namespace `PHPUnit_Util_XML` compat shim, which targeted PHPUnit 4.x and has been dead code since the PHP 8.2 requirement was introduced. Add native parameter and return types throughout, and align the `assertHtml` parameter names with the conventional `$expected` / `$actual` pair so the signature reads consistently with PHPUnit's own assertion API. --- src/Test/TestCase.php | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Test/TestCase.php b/src/Test/TestCase.php index 7076fad7..ed98434c 100644 --- a/src/Test/TestCase.php +++ b/src/Test/TestCase.php @@ -4,37 +4,31 @@ use DOMDocument; use ipl\Html\ValidHtml; +use PHPUnit\Framework\TestCase as BaseTestCase; -// phpcs:disable -if (class_exists('PHPUnit_Util_XML')) { - // Support older PHPUnit versions - class_alias('PHPUnit_Util_XML', 'PHPUnit\\Util\\Xml'); -} - -// phpcs:enable - -abstract class TestCase extends \PHPUnit\Framework\TestCase +abstract class TestCase extends BaseTestCase { /** * Assert that HTML is equal * - * @param string $expectedHtml + * @param string $expected * @param ValidHtml $actual */ - protected function assertHtml($expectedHtml, ValidHtml $actualHtml) + protected function assertHtml(string $expected, ValidHtml $actual): void { $expectedHtml = str_replace( "\n", '', - preg_replace('/^\s+/m', '', trim($expectedHtml)) + preg_replace('/^\s+/m', '', trim($expected)) ); + $actualHtml = $actual->render(); - $expected = new DOMDocument(); - $this->assertTrue($expected->loadHTML($expectedHtml), 'Expected HTML is not valid'); - $actual = new DOMDocument(); - $this->assertTrue($actual->loadHTML($actualHtml->render()), 'Actual HTML is not valid'); + $expectedDom = new DOMDocument(); + $this->assertTrue($expectedDom->loadHTML($expectedHtml), 'Expected HTML is not valid'); + $actualDom = new DOMDocument(); + $this->assertTrue($actualDom->loadHTML($actualHtml), 'Actual HTML is not valid'); - $this->assertEquals($expected, $actual); + $this->assertEquals($expectedDom, $actualDom); } /** @@ -42,7 +36,7 @@ protected function assertHtml($expectedHtml, ValidHtml $actualHtml) * processed must have a root node, e.g. the HTML `foobar` would always fail with "Extra content at * the end of the document". {@link assertHtml()} just does the job. */ - protected function assertRendersHtml($html, ValidHtml $element) + protected function assertRendersHtml(string $html, ValidHtml $element): void { $this->assertXmlStringEqualsXmlString($html, $element->render()); }