Skip to content

Commit 91acbdf

Browse files
authored
Rename test suites in phpunit.xml.dist (#1944)
* Enforce test run on `phpunit.xml.dist` changes * Make `HTMLTypeTest` PHP version dependant Due to internal dom differences * Fixed wrong HTML detection on PHP 8.4
1 parent 506fb1a commit 91acbdf

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

.github/workflows/test-suite.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- 'examples/**'
99
- 'composer.lock'
1010
- 'composer.json'
11+
- 'phpunit.xml.dist'
1112
push:
1213
branches: [ 1.x ]
1314
paths:
@@ -18,6 +19,7 @@ on:
1819
- 'examples/**'
1920
- 'composer.lock'
2021
- 'composer.json'
22+
- 'phpunit.xml.dist'
2123
schedule:
2224
- cron: '0 4 * * *'
2325
workflow_dispatch:
@@ -50,4 +52,4 @@ jobs:
5052
uses: ./.github/workflows/job-mutation-tests.yml
5153

5254
benchmark-tests:
53-
uses: ./.github/workflows/job-benchmark-tests.yml
55+
uses: ./.github/workflows/job-benchmark-tests.yml

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@
7272
<testsuite name="lib-parquet-viewer-integration">
7373
<directory>src/lib/parquet-viewer/tests/Flow/ParquetViewer/Tests/Integration</directory>
7474
</testsuite>
75-
<testsuite name="snappy-integration">
75+
<testsuite name="lib-snappy-integration">
7676
<directory>src/lib/snappy/tests/Flow/Snappy/Tests/Integration</directory>
7777
</testsuite>
78-
<testsuite name="types-unit">
78+
<testsuite name="lib-types-unit">
7979
<directory>src/lib/types/tests/Flow/Types/Tests/Unit</directory>
8080
</testsuite>
8181
<testsuite name="bridge-filesystem-azure-unit">

src/lib/types/src/Flow/Types/Type/Native/String/StringTypeChecker.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,19 @@ public function isHTML() : bool
119119
return false;
120120
}
121121

122-
if (\class_exists('\Dom\HTMLDocument', false)) {
123-
$options = \LIBXML_HTML_NOIMPLIED;
122+
if (\preg_match('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im', $this->string) === 1) {
123+
if (\class_exists('\Dom\HTMLDocument', false)) {
124+
$options = \LIBXML_HTML_NOIMPLIED;
124125

125-
if (defined('Dom\HTML_NO_DEFAULT_NS')) {
126-
$options |= constant('\Dom\HTML_NO_DEFAULT_NS');
126+
if (defined('Dom\HTML_NO_DEFAULT_NS')) {
127+
$options |= constant('\Dom\HTML_NO_DEFAULT_NS');
128+
}
129+
130+
$doc = @HTMLDocument::createFromString($this->string, $options);
131+
132+
return $doc->saveHtml() === $this->string;
127133
}
128134

129-
HTMLDocument::createFromString($this->string, $options);
130-
} elseif (\preg_match('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im', $this->string) === 1) {
131135
try {
132136
\libxml_use_internal_errors(true);
133137

src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use function Flow\Types\DSL\{type_from_array, type_html};
88
use Flow\Types\Exception\{CastingException, InvalidTypeException};
99
use Flow\Types\Value\HTMLDocument;
10-
use PHPUnit\Framework\Attributes\DataProvider;
10+
use PHPUnit\Framework\Attributes\{DataProvider, RequiresPhp};
1111
use PHPUnit\Framework\TestCase;
1212

1313
final class HTMLTypeTest extends TestCase
@@ -60,7 +60,7 @@ public static function assert_data_provider() : \Generator
6060
];
6161
}
6262

63-
public static function cast_data_provider() : \Generator
63+
public static function cast_data_provider_php82() : \Generator
6464
{
6565
yield 'string to HTML' => [
6666
'value' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html>',
@@ -86,6 +86,29 @@ public static function cast_data_provider() : \Generator
8686
];
8787
}
8888

89+
public static function cast_data_provider_php84() : \Generator
90+
{
91+
yield 'string to HTML' => [
92+
'value' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html>',
93+
'expected' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html>',
94+
'exceptionClass' => null,
95+
];
96+
97+
yield 'incomplete string to HTML' => [
98+
'value' => '<div><span>1</span></div>',
99+
'expected' => <<<'HTML'
100+
<div><span>1</span></div>
101+
HTML,
102+
'exceptionClass' => null,
103+
];
104+
105+
yield 'object to HTML' => [
106+
'value' => new \stdClass(),
107+
'expected' => null,
108+
'exceptionClass' => CastingException::class,
109+
];
110+
}
111+
89112
public static function is_valid_data_provider() : \Generator
90113
{
91114
yield 'valid HTMLDocument' => [
@@ -120,8 +143,22 @@ public function test_assert(mixed $value, ?string $exceptionClass = null) : void
120143
}
121144
}
122145

123-
#[DataProvider('cast_data_provider')]
124-
public function test_cast(mixed $value, mixed $expected, ?string $exceptionClass) : void
146+
#[RequiresPhp('< 8.4')]
147+
#[DataProvider('cast_data_provider_php82')]
148+
public function test_cast_php82(mixed $value, mixed $expected, ?string $exceptionClass) : void
149+
{
150+
if ($exceptionClass !== null) {
151+
$this->expectException($exceptionClass);
152+
type_html()->cast($value);
153+
} else {
154+
$result = type_html()->cast($value);
155+
self::assertSame($expected, $result->toString());
156+
}
157+
}
158+
159+
#[RequiresPhp('>= 8.4')]
160+
#[DataProvider('cast_data_provider_php84')]
161+
public function test_cast_php84(mixed $value, mixed $expected, ?string $exceptionClass) : void
125162
{
126163
if ($exceptionClass !== null) {
127164
$this->expectException($exceptionClass);

src/lib/types/tests/Flow/Types/Tests/Unit/Value/HTMLDocumentTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ final class HTMLDocumentTest extends TestCase
1414
#[RequiresPhp('>= 8.4')]
1515
public function test_create_with_dom_document_html_on_newer() : void
1616
{
17-
$doc = \Dom\HTMLDocument::createFromString('<html><body><div><span>bar</span></div></body></html>');
17+
$doc = \Dom\HTMLDocument::createFromString('<html><body><div><span>bar</span></div></body></html>', \LIBXML_HTML_NOIMPLIED);
1818

1919
$document = new HTMLDocument($doc);
2020

21-
self::assertSame('<html><head></head><body><div><span>bar</span></div></body></html>', (string) $document);
21+
self::assertSame('<html><body><div><span>bar</span></div></body></html>', (string) $document);
2222
}
2323

24-
#[RequiresPhp('<= 8.4')]
24+
#[RequiresPhp('< 8.4')]
2525
public function test_create_with_dom_document_html_on_old() : void
2626
{
2727
$doc = new \DOMDocument();
@@ -40,7 +40,7 @@ public function test_create_with_invalid_html_on_newer() : void
4040
self::assertSame('invalid', (string) $document);
4141
}
4242

43-
#[RequiresPhp('<= 8.4')]
43+
#[RequiresPhp('< 8.4')]
4444
public function test_create_with_invalid_html_on_old() : void
4545
{
4646
$document = new HTMLDocument('invalid');
@@ -57,7 +57,7 @@ public function test_create_with_proper_html_on_newer() : void
5757
self::assertSame($html, (string) $document);
5858
}
5959

60-
#[RequiresPhp('<= 8.4')]
60+
#[RequiresPhp('< 8.4')]
6161
public function test_create_with_proper_html_on_old() : void
6262
{
6363
$html = '<html><body><div><span>bar</span></div></body></html>';

0 commit comments

Comments
 (0)