xref: /PHP-8.3/ext/intl/tests/msgfmt_fail2.phpt (revision 74859783)
1--TEST--
2msgfmt creation failures icu >= 4.8
3--EXTENSIONS--
4intl
5--FILE--
6<?php
7
8function err($fmt) {
9    if(!$fmt) {
10        echo var_export(intl_get_error_message(), true)."\n";
11    }
12}
13
14function print_exception($e) {
15    echo "\n" . get_class($e) . ": " . $e->getMessage()
16       . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
17}
18
19function crt($t, $l, $s) {
20    switch(true) {
21        case $t == "O":
22            try {
23                return new MessageFormatter($l, $s);
24            } catch (Throwable $e) {
25                print_exception($e);
26                return null;
27            }
28            break;
29        case $t == "C":
30            try {
31                return MessageFormatter::create($l, $s);
32            } catch (Throwable $e) {
33                print_exception($e);
34                return null;
35            }
36            break;
37        case $t == "P":
38            try {
39                return msgfmt_create($l, $s);
40            } catch (Throwable $e) {
41                print_exception($e);
42                return null;
43            }
44            break;
45    }
46}
47
48$args = array(
49    array(null, null),
50    array("whatever", "{0,whatever}"),
51    array(array(), array()),
52    array("en", "{0,choice}"),
53    array("fr", "{0,"),
54    array("en_US", "\xD0"),
55);
56
57try {
58    $fmt = new MessageFormatter();
59} catch (TypeError $e) {
60    print_exception($e);
61    $fmt = null;
62}
63err($fmt);
64try {
65    $fmt = msgfmt_create();
66} catch (TypeError $e) {
67    print_exception($e);
68    $fmt = null;
69}
70err($fmt);
71try {
72    $fmt = MessageFormatter::create();
73} catch (TypeError $e) {
74    print_exception($e);
75    $fmt = null;
76}
77err($fmt);
78try {
79    $fmt = new MessageFormatter('en');
80} catch (TypeError $e) {
81    print_exception($e);
82    $fmt = null;
83}
84err($fmt);
85try {
86    $fmt = msgfmt_create('en');
87} catch (TypeError $e) {
88    print_exception($e);
89    $fmt = null;
90}
91err($fmt);
92try {
93    $fmt = MessageFormatter::create('en');
94} catch (TypeError $e) {
95    print_exception($e);
96    $fmt = null;
97}
98err($fmt);
99
100foreach($args as $arg) {
101    $fmt = crt("O", $arg[0], $arg[1]);
102    err($fmt);
103    $fmt = crt("C", $arg[0], $arg[1]);
104    err($fmt);
105    $fmt = crt("P", $arg[0], $arg[1]);
106    err($fmt);
107}
108
109?>
110--EXPECTF--
111ArgumentCountError: MessageFormatter::__construct() expects exactly 2 arguments, 0 given in %s on line %d
112'U_ZERO_ERROR'
113
114ArgumentCountError: msgfmt_create() expects exactly 2 arguments, 0 given in %s on line %d
115'U_ZERO_ERROR'
116
117ArgumentCountError: MessageFormatter::create() expects exactly 2 arguments, 0 given in %s on line %d
118'U_ZERO_ERROR'
119
120ArgumentCountError: MessageFormatter::__construct() expects exactly 2 arguments, 1 given in %s on line %d
121'U_ZERO_ERROR'
122
123ArgumentCountError: msgfmt_create() expects exactly 2 arguments, 1 given in %s on line %d
124'U_ZERO_ERROR'
125
126ArgumentCountError: MessageFormatter::create() expects exactly 2 arguments, 1 given in %s on line %d
127'U_ZERO_ERROR'
128
129Deprecated: MessageFormatter::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
130
131Deprecated: MessageFormatter::__construct(): Passing null to parameter #2 ($pattern) of type string is deprecated in %s on line %d
132
133IntlException: msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
134'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
135
136Deprecated: MessageFormatter::create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
137
138Deprecated: MessageFormatter::create(): Passing null to parameter #2 ($pattern) of type string is deprecated in %s on line %d
139'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
140
141Deprecated: msgfmt_create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
142
143Deprecated: msgfmt_create(): Passing null to parameter #2 ($pattern) of type string is deprecated in %s on line %d
144'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
145
146IntlException: msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
147'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
148'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
149'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
150
151TypeError: MessageFormatter::__construct(): Argument #1 ($locale) must be of type string, array given in %s on line %d
152'U_ZERO_ERROR'
153
154TypeError: MessageFormatter::create(): Argument #1 ($locale) must be of type string, array given in %s on line %d
155'U_ZERO_ERROR'
156
157TypeError: msgfmt_create(): Argument #1 ($locale) must be of type string, array given in %s on line %d
158'U_ZERO_ERROR'
159
160IntlException: pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR in %s on line %d
161'pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR'
162'pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR'
163'pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR'
164
165IntlException: msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES in %s on line %d
166'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
167'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
168'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
169
170IntlException: msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND in %s on line %d
171'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
172'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
173'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
174