1--TEST--
2Dom\HTMLDocument serialization with a failing stream
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8class FailingWrapper {
9    public $context;
10    public $fail = false;
11
12    public function stream_open($path, $mode, $options, &$opened_path) {
13        return true;
14    }
15
16    public function stream_write(string $data): int {
17        if ($this->fail) {
18            throw new Error("fail");
19        }
20        $this->fail = true;
21        var_dump($data);
22        return strlen($data);
23    }
24
25    public function stream_eof() {
26        return false;
27    }
28
29    public function stream_close() {
30        return true;
31    }
32}
33
34stream_wrapper_register("failing", "FailingWrapper");
35
36$dom = Dom\HTMLDocument::createEmpty();
37$root = $dom->appendChild($dom->createElement("root"));
38$dom->saveHtmlFile("failing://foo");
39
40?>
41--EXPECTF--
42string(1) "<"
43
44Fatal error: Uncaught Error: fail in %s:%d
45Stack trace:
46#0 [internal function]: FailingWrapper->stream_write('root')
47#1 %s(%d): Dom\HTMLDocument->saveHtmlFile('failing://foo')
48#2 {main}
49  thrown in %s on line %d
50