IntegerLiteralCaseFixerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\Casing;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Casing\IntegerLiteralCaseFixer
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Casing\IntegerLiteralCaseFixer>
  20. */
  21. final class IntegerLiteralCaseFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<int|string, array{0: string, 1?: string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield [
  36. '<?php $foo1 = 0xFF; $foo2 = 0xDEFA; $foo3 = 0xFA; $foo4 = 0xFA;',
  37. '<?php $foo1 = 0XFF; $foo2 = 0xdefa; $foo3 = 0Xfa; $foo4 = 0xFA;',
  38. ];
  39. yield [
  40. '<?php $foo = 0xA1FB20;',
  41. '<?php $foo = 0xa1fb20;',
  42. ];
  43. yield [
  44. '<?php $foo = -0xA1FB20;',
  45. '<?php $foo = -0xa1fb20;',
  46. ];
  47. yield [
  48. '<?php $foo = 0b1101;',
  49. '<?php $foo = 0B1101;',
  50. ];
  51. yield [
  52. '<?php $A = 1_234_567;',
  53. ];
  54. yield [
  55. '<?php $A = +0xAA_FF_00;',
  56. '<?php $A = +0Xaa_ff_00;',
  57. ];
  58. yield [
  59. '<?php $A = -0x00_AA_FF_00;',
  60. '<?php $A = -0X00_aa_ff_00;',
  61. ];
  62. yield 'bin_PHP_INT_MAX' => [
  63. '<?php $foo = 0b111111111111111111111111111111111111111111111111111111111111111;',
  64. '<?php $foo = 0B111111111111111111111111111111111111111111111111111111111111111;',
  65. ];
  66. yield 'hex_plus_PHP_INT_MAX' => [
  67. '<?php $foo = +0x7FFFFFFFFFFFFFFF;',
  68. '<?php $foo = +0X7fffffffffffffff;',
  69. ];
  70. yield 'hex_minus_PHP_INT_MAX' => [
  71. '<?php $foo = -0x7FFFFFFFFFFFFFFF;',
  72. '<?php $foo = -0X7fffffffffffffff;',
  73. ];
  74. }
  75. /**
  76. * @dataProvider provideFix81Cases
  77. *
  78. * @requires PHP 8.1
  79. */
  80. public function testFix81(string $expected, ?string $input = null): void
  81. {
  82. $this->doTest($expected, $input);
  83. }
  84. /**
  85. * @return iterable<array{string, string}>
  86. */
  87. public static function provideFix81Cases(): iterable
  88. {
  89. yield [
  90. '<?php $foo = 0o123;',
  91. '<?php $foo = 0O123;',
  92. ];
  93. yield [
  94. '<?php $foo = -0o123;',
  95. '<?php $foo = -0O123;',
  96. ];
  97. }
  98. }