1--TEST--
2Dom\XMLDocument::createFromString() with overrideEncoding
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8try {
9    Dom\XMLDocument::createFromString(file_get_contents(__DIR__ . '/dummy.xml'), overrideEncoding: 'nonexistent');
10} catch (ValueError $e) {
11    echo $e->getMessage(), "\n";
12}
13
14// The override encoding matches with the document encoding attribute
15$dom = Dom\XMLDocument::createFromString(file_get_contents(__DIR__ . '/dummy.xml'), overrideEncoding: 'UTF-8');
16var_dump($dom->documentElement->lastChild->textContent);
17var_dump($dom->charset);
18
19// The override encoding mismatches with the document encoding attribute
20$dom = Dom\XMLDocument::createFromString(file_get_contents(__DIR__ . '/dummy.xml'), overrideEncoding: 'Windows-1252');
21var_dump($dom->documentElement->lastChild->textContent);
22var_dump($dom->charset);
23
24?>
25--EXPECT--
26Dom\XMLDocument::createFromString(): Argument #3 ($overrideEncoding) must be a valid document encoding
27string(2) "é"
28string(5) "UTF-8"
29string(4) "é"
30string(12) "Windows-1252"
31