1--TEST--
2DOM\HTMLDocument::createFromFile() with working stream wrapper
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8class EchoUriWrapper {
9    private int $position = 0;
10    private string $data;
11    public $context;
12
13    public function stream_open($path, $mode, $options, &$opened_path) {
14        $this->data = substr($path, 6);
15        return true;
16    }
17
18    public function stream_read($count) {
19        $ret = substr($this->data, $this->position, $count);
20        $this->position += $count;
21        return $ret;
22    }
23
24    public function stream_eof() {
25        return $this->position >= strlen($this->data);
26    }
27
28    public function stream_close() {
29        return true;
30    }
31}
32
33stream_wrapper_register("euw", EchoUriWrapper::class, 0);
34
35echo "--- Stream wrapper case ---\n";
36
37$dom = DOM\HTMLDocument::createFromFile("euw://<p>hello</p>");
38echo $dom->saveHTML(), "\n";
39
40echo "--- Stream wrapper in two chunks case ---\n";
41
42libxml_use_internal_errors(true);
43// To properly test this, keep the 4096 in sync with document.c's input stream buffer size.
44$dom = DOM\HTMLDocument::createFromFile("euw://<!doctype html><html>" . str_repeat("\n", 4096-22) . "<></html>");
45echo $dom->saveHTML(), "\n";
46
47foreach (libxml_get_errors() as $error) {
48    var_dump($error->line, $error->column);
49}
50
51?>
52--EXPECTF--
53--- Stream wrapper case ---
54
55Warning: DOM\HTMLDocument::createFromFile(): tree error unexpected-token-in-initial-mode in euw://<p>hello</p>, line: 1, column: 2 in %s on line %d
56<html><head></head><body><p>hello</p></body></html>
57--- Stream wrapper in two chunks case ---
58<!DOCTYPE html><html><head></head><body>&lt;&gt;</body></html>
59int(4075)
60int(2)
61