msgfmt_fail2.phpt 5.7 KB

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