xref: /PHP-8.0/ext/intl/tests/msgfmt_fail2.phpt (revision 74cf2eb8)
1--TEST--
2msgfmt creation failures icu >= 4.8
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip intl extension not loaded'; ?>
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
129IntlException: msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
130'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
131'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
132'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
133
134IntlException: msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
135'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
136'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
137'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
138
139TypeError: MessageFormatter::__construct(): Argument #1 ($locale) must be of type string, array given in %s on line %d
140'U_ZERO_ERROR'
141
142TypeError: MessageFormatter::create(): Argument #1 ($locale) must be of type string, array given in %s on line %d
143'U_ZERO_ERROR'
144
145TypeError: msgfmt_create(): Argument #1 ($locale) must be of type string, array given in %s on line %d
146'U_ZERO_ERROR'
147
148IntlException: pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR in %s on line %d
149'pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR'
150'pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR'
151'pattern syntax error (parse error at offset 1, after "{", before or at "0,choice}"): U_PATTERN_SYNTAX_ERROR'
152
153IntlException: msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES in %s on line %d
154'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
155'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
156'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
157
158IntlException: msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND in %s on line %d
159'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
160'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
161'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
162