PHP7_3.test 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. --TEST--
  2. PHP 7.3 test.
  3. --RULESET--
  4. {
  5. "@Symfony": true,
  6. "@Symfony:risky": true,
  7. "@PHP73Migration": true,
  8. "@PHP71Migration:risky": true,
  9. "list_syntax": {"syntax": "short"},
  10. "mb_str_functions": true,
  11. "method_chaining_indentation": true,
  12. "multiline_whitespace_before_semicolons": true,
  13. "native_function_invocation": {"include": ["get_class"]},
  14. "no_unset_cast": true,
  15. "no_unset_on_property": true,
  16. "php_unit_dedicate_assert": true,
  17. "php_unit_expectation": true,
  18. "php_unit_mock": true,
  19. "php_unit_strict": true,
  20. "php_unit_test_case_static_method_calls": {"call_type": "this"},
  21. "strict_param": true
  22. }
  23. --REQUIREMENTS--
  24. {"php": 70300, "php<": 80000}
  25. --EXPECT--
  26. <?php
  27. declare(strict_types=1);
  28. function foo($a = true): void // In PHP 8.0: true, false and null are converted from special-cased constants into reserved keywords.
  29. {
  30. }
  31. $firstKey = array_key_first($items);
  32. $lastKey = array_key_last($items);
  33. is_countable($foo);
  34. // https://wiki.php.net/rfc/list_reference_assignment
  35. [$a, &$b] = $array; // `list_syntax` rule
  36. // https://github.com/php/php-src/pull/2978 instanceof now allows literals as the first operand (the result is always false).
  37. null instanceof \stdClass;
  38. // https://wiki.php.net/rfc/trailing-comma-function-calls Trailing commas in function and method calls are now allowed.
  39. foo(
  40. $arg,
  41. $arg2,
  42. );
  43. __DIR__; // `dir_constant` rule
  44. dirname($path, 3); // `combine_nested_dirname` rule
  45. $foo->__invoke(1); // `magic_method_casing` rule
  46. implode('', $pieces); // `implode_call` rule
  47. implode('', $pieces); // `implode_call` rule
  48. null === $var; // `is_null` rule
  49. mb_strpos($a, $b); // `mb_str_functions` rule
  50. sample('foo', 'foobarbaz', 'baz'); // `method_argument_space` rule
  51. $user->setEmail('voff.web@gmail.com') // `method_chaining_indentation` rule
  52. ->setPassword('233434');
  53. $a = (int) $b; // `modernize_types_casting` rule
  54. $this->method1() // `multiline_whitespace_before_semicolons` rule
  55. ->method2(3);
  56. mb_strlen($str); // `native_function_casing` rule
  57. $c = \get_class($d); // `native_function_invocation` rule
  58. $a = rtrim($b); // `no_alias_functions` rule
  59. $foo->bar($arg1, $arg2); // `no_spaces_inside_parenthesis` rule
  60. final class MyClass extends \PHPUnit_Framework_TestCase
  61. {
  62. public function testFoo(): void
  63. {
  64. $this->assertTrue($a); // `php_unit_construct` rule
  65. $this->assertNan($a); // `php_unit_dedicate_assert` rule
  66. $this->expectException('RuntimeException');
  67. $this->expectExceptionMessage('Msg');
  68. $this->expectExceptionCode(123); // `php_unit_expectation` rule
  69. $this->createMock('Foo'); // `php_unit_mock` rule
  70. $this->assertSame(1, 2); // `php_unit_test_case_static_method_calls` rule
  71. $this->assertSame(1, $a, ''); // `php_unit_strict` rule
  72. }
  73. }
  74. $a ** 1; // `pow_to_exponentiation` rule
  75. random_int($a, $b); // `random_api_migration` rule
  76. $foo = (int) $foo; // `set_type_to_cast` rule
  77. in_array($b, $c, true); // `strict_param` rule
  78. @trigger_error('Warning.', \E_USER_DEPRECATED); // `error_suppression` rule
  79. foo(null === $a); // `yoda_style` rule
  80. $a = null; // `no_unset_cast` rule
  81. $foo->bar = null; // `no_unset_on_property` rule
  82. // https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
  83. $a = <<<'EOD'
  84. abc
  85. def
  86. ghi
  87. EOD;
  88. $a = [<<<'EOD'
  89. foo
  90. EOD, <<<'EOD'
  91. bar
  92. EOD
  93. ];
  94. $a = [
  95. <<<'EOD'
  96. foo
  97. EOD,
  98. <<<'EOD'
  99. bar
  100. EOD,
  101. ];
  102. foo(
  103. <<<'EOD'
  104. bar
  105. EOD,
  106. 'baz'
  107. );
  108. --INPUT--
  109. <?php
  110. function foo($a = TRUE) // In PHP 8.0: true, false and null are converted from special-cased constants into reserved keywords.
  111. {
  112. }
  113. $firstKey = ARRAY_KEY_FIRST($items);
  114. $lastKey = ARRAY_Key_last($items);
  115. IS_COUNTABLE($foo);
  116. // https://wiki.php.net/rfc/list_reference_assignment
  117. list($a, &$b) = $array; // `list_syntax` rule
  118. // https://github.com/php/php-src/pull/2978 instanceof now allows literals as the first operand (the result is always false).
  119. null instanceof \stdClass;
  120. // https://wiki.php.net/rfc/trailing-comma-function-calls Trailing commas in function and method calls are now allowed.
  121. foo(
  122. $arg,
  123. $arg2,
  124. );
  125. dirname(__FILE__, ); // `dir_constant` rule
  126. dirname(dirname(dirname($path, ), ), ); // `combine_nested_dirname` rule
  127. $foo->__INVOKE(1, ); // `magic_method_casing` rule
  128. implode($pieces, '', ); // `implode_call` rule
  129. implode($pieces, ); // `implode_call` rule
  130. is_null($var, ); // `is_null` rule
  131. strpos($a, $b, ); // `mb_str_functions` rule
  132. sample('foo', 'foobarbaz', 'baz' , ); // `method_argument_space` rule
  133. $user->setEmail('voff.web@gmail.com', ) // `method_chaining_indentation` rule
  134. ->setPassword('233434', );
  135. $a = intval($b, ); // `modernize_types_casting` rule
  136. $this->method1() // `multiline_whitespace_before_semicolons` rule
  137. ->method2(3, )
  138. ;
  139. STRLEN($str, ); // `native_function_casing` rule
  140. $c = get_class($d, ); // `native_function_invocation` rule
  141. $a = chop($b, ); // `no_alias_functions` rule
  142. $foo->bar( $arg1, $arg2, );// `no_spaces_inside_parenthesis` rule
  143. final class MyTest extends \PHPUnit_Framework_TestCase
  144. {
  145. public function testFoo(): void
  146. {
  147. $this->assertSame(true, $a, ); // `php_unit_construct` rule
  148. $this->assertTrue(is_nan($a, ), ); // `php_unit_dedicate_assert` rule
  149. $this->setExpectedException('RuntimeException', 'Msg', 123, ); // `php_unit_expectation` rule
  150. $this->getMock('Foo', ); // `php_unit_mock` rule
  151. static::assertSame(1, 2, ); // `php_unit_test_case_static_method_calls` rule
  152. self::assertEquals(1, $a, '', ); // `php_unit_strict` rule
  153. }
  154. }
  155. pow($a, 1, ); // `pow_to_exponentiation` rule
  156. rand($a, $b, ); // `random_api_migration` rule
  157. settype($foo, "integer", ); // `set_type_to_cast` rule
  158. in_array($b, $c, ); // `strict_param` rule
  159. trigger_error('Warning.', E_USER_DEPRECATED, ); // `error_suppression` rule
  160. foo($a === null, ); // `yoda_style` rule
  161. $a =(unset)$z; // `no_unset_cast` rule
  162. unset($foo->bar,); // `no_unset_on_property` rule
  163. // https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
  164. $a = <<<'EOD'
  165. abc
  166. def
  167. ghi
  168. EOD;
  169. $a = [<<<'EOD'
  170. foo
  171. EOD
  172. , <<<'EOD'
  173. bar
  174. EOD
  175. ];
  176. $a = [
  177. <<<'EOD'
  178. foo
  179. EOD
  180. ,
  181. <<<'EOD'
  182. bar
  183. EOD
  184. ];
  185. foo(
  186. <<<'EOD'
  187. bar
  188. EOD
  189. ,
  190. 'baz'
  191. );