OctalNotationFixerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\Basic;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author SpacePossum
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Basic\OctalNotationFixer
  20. *
  21. * @requires PHP 8.1
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Basic\OctalNotationFixer>
  24. */
  25. final class OctalNotationFixerTest extends AbstractFixerTestCase
  26. {
  27. /**
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix(string $expected, ?string $input = null): void
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @return iterable<array{0: string, 1?: string}>
  36. */
  37. public static function provideFixCases(): iterable
  38. {
  39. yield [
  40. '<?php
  41. $a = 0;
  42. $b = \'0\';
  43. $foo = 0b01;
  44. $foo = 0x01;
  45. $foo = 0B01;
  46. $foo = 0X01;
  47. $foo = 0b0;
  48. $foo = 0x0;
  49. $foo = 0B0;
  50. $foo = 0X0;
  51. $foo = 1;
  52. $foo = 10;
  53. ',
  54. ];
  55. yield [
  56. '<?php $foo = 0o0000;',
  57. '<?php $foo = 00000;',
  58. ];
  59. yield [
  60. '<?php
  61. $foo = 0o123;
  62. $foo = 0o1;
  63. ',
  64. '<?php
  65. $foo = 0123;
  66. $foo = 01;
  67. ',
  68. ];
  69. yield [
  70. '<?php $foo = 0o1_234;',
  71. '<?php $foo = 01_234;',
  72. ];
  73. yield [
  74. '<?php $foo = +0o1_234;',
  75. '<?php $foo = +01_234;',
  76. ];
  77. yield [
  78. '<?php $foo = -0o123_456;',
  79. '<?php $foo = -0_123_456;',
  80. ];
  81. }
  82. }