Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- 'examples/**'
- 'composer.lock'
- 'composer.json'
- 'phpunit.xml.dist'
push:
branches: [ 1.x ]
paths:
Expand All @@ -18,6 +19,7 @@ on:
- 'examples/**'
- 'composer.lock'
- 'composer.json'
- 'phpunit.xml.dist'
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
Expand Down Expand Up @@ -50,4 +52,4 @@ jobs:
uses: ./.github/workflows/job-mutation-tests.yml

benchmark-tests:
uses: ./.github/workflows/job-benchmark-tests.yml
uses: ./.github/workflows/job-benchmark-tests.yml
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
<testsuite name="lib-parquet-viewer-integration">
<directory>src/lib/parquet-viewer/tests/Flow/ParquetViewer/Tests/Integration</directory>
</testsuite>
<testsuite name="snappy-integration">
<testsuite name="lib-snappy-integration">
<directory>src/lib/snappy/tests/Flow/Snappy/Tests/Integration</directory>
</testsuite>
<testsuite name="types-unit">
<testsuite name="lib-types-unit">
<directory>src/lib/types/tests/Flow/Types/Tests/Unit</directory>
</testsuite>
<testsuite name="bridge-filesystem-azure-unit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,19 @@ public function isHTML() : bool
return false;
}

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

if (defined('Dom\HTML_NO_DEFAULT_NS')) {
$options |= constant('\Dom\HTML_NO_DEFAULT_NS');
if (defined('Dom\HTML_NO_DEFAULT_NS')) {
$options |= constant('\Dom\HTML_NO_DEFAULT_NS');
}

$doc = @HTMLDocument::createFromString($this->string, $options);

return $doc->saveHtml() === $this->string;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use function Flow\Types\DSL\{type_from_array, type_html};
use Flow\Types\Exception\{CastingException, InvalidTypeException};
use Flow\Types\Value\HTMLDocument;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\{DataProvider, RequiresPhp};
use PHPUnit\Framework\TestCase;

final class HTMLTypeTest extends TestCase
Expand Down Expand Up @@ -60,7 +60,7 @@ public static function assert_data_provider() : \Generator
];
}

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

public static function cast_data_provider_php84() : \Generator
{
yield 'string to HTML' => [
'value' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html>',
'expected' => '<!DOCTYPE html><html lang="en"><body><div><span>1</span></div></body></html>',
'exceptionClass' => null,
];

yield 'incomplete string to HTML' => [
'value' => '<div><span>1</span></div>',
'expected' => <<<'HTML'
<div><span>1</span></div>
HTML,
'exceptionClass' => null,
];

yield 'object to HTML' => [
'value' => new \stdClass(),
'expected' => null,
'exceptionClass' => CastingException::class,
];
}

public static function is_valid_data_provider() : \Generator
{
yield 'valid HTMLDocument' => [
Expand Down Expand Up @@ -120,8 +143,22 @@ public function test_assert(mixed $value, ?string $exceptionClass = null) : void
}
}

#[DataProvider('cast_data_provider')]
public function test_cast(mixed $value, mixed $expected, ?string $exceptionClass) : void
#[RequiresPhp('< 8.4')]
#[DataProvider('cast_data_provider_php82')]
public function test_cast_php82(mixed $value, mixed $expected, ?string $exceptionClass) : void
{
if ($exceptionClass !== null) {
$this->expectException($exceptionClass);
type_html()->cast($value);
} else {
$result = type_html()->cast($value);
self::assertSame($expected, $result->toString());
}
}

#[RequiresPhp('>= 8.4')]
#[DataProvider('cast_data_provider_php84')]
public function test_cast_php84(mixed $value, mixed $expected, ?string $exceptionClass) : void
{
if ($exceptionClass !== null) {
$this->expectException($exceptionClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ final class HTMLDocumentTest extends TestCase
#[RequiresPhp('>= 8.4')]
public function test_create_with_dom_document_html_on_newer() : void
{
$doc = \Dom\HTMLDocument::createFromString('<html><body><div><span>bar</span></div></body></html>');
$doc = \Dom\HTMLDocument::createFromString('<html><body><div><span>bar</span></div></body></html>', \LIBXML_HTML_NOIMPLIED);

$document = new HTMLDocument($doc);

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

#[RequiresPhp('<= 8.4')]
#[RequiresPhp('< 8.4')]
public function test_create_with_dom_document_html_on_old() : void
{
$doc = new \DOMDocument();
Expand All @@ -40,7 +40,7 @@ public function test_create_with_invalid_html_on_newer() : void
self::assertSame('invalid', (string) $document);
}

#[RequiresPhp('<= 8.4')]
#[RequiresPhp('< 8.4')]
public function test_create_with_invalid_html_on_old() : void
{
$document = new HTMLDocument('invalid');
Expand All @@ -57,7 +57,7 @@ public function test_create_with_proper_html_on_newer() : void
self::assertSame($html, (string) $document);
}

#[RequiresPhp('<= 8.4')]
#[RequiresPhp('< 8.4')]
public function test_create_with_proper_html_on_old() : void
{
$html = '<html><body><div><span>bar</span></div></body></html>';
Expand Down