LowercaseCastFixerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\CastNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer
  18. */
  19. final class LowercaseCastFixerTest extends AbstractFixerTestCase
  20. {
  21. /**
  22. * @dataProvider provideFixCases
  23. */
  24. public function testFix(string $expected, ?string $input = null): void
  25. {
  26. $this->doTest($expected, $input);
  27. }
  28. /**
  29. * @return iterable<array{0: non-empty-string, 1?: non-empty-string}>
  30. */
  31. public static function provideFixCases(): iterable
  32. {
  33. $types = ['boolean', 'bool', 'integer', 'int', 'double', 'float', 'float', 'string', 'array', 'object', 'binary'];
  34. foreach ($types as $from) {
  35. yield from self::createCasesFor($from);
  36. }
  37. }
  38. /**
  39. * @dataProvider provideFixPre80Cases
  40. *
  41. * @requires PHP <8.0
  42. */
  43. public function testFixPre80(string $expected, string $input = null): void
  44. {
  45. $this->doTest($expected, $input);
  46. }
  47. /**
  48. * @return iterable<array{0: non-empty-string, 1?: non-empty-string}>
  49. */
  50. public static function provideFixPre80Cases(): iterable
  51. {
  52. yield from self::createCasesFor('unset');
  53. }
  54. /**
  55. * @dataProvider provideFix74DeprecatedCases
  56. *
  57. * @group legacy
  58. *
  59. * @requires PHP <8.0
  60. */
  61. public function testFix74Deprecated(string $expected, ?string $input = null): void
  62. {
  63. $this->expectDeprecation('The (real) cast is deprecated, use (float) instead');
  64. $this->doTest($expected, $input);
  65. }
  66. /**
  67. * @return iterable<array{0: non-empty-string, 1?: non-empty-string}>
  68. */
  69. public static function provideFix74DeprecatedCases(): iterable
  70. {
  71. return self::createCasesFor('real');
  72. }
  73. /**
  74. * @return iterable<array{0: non-empty-string, 1?: non-empty-string}>
  75. */
  76. private static function createCasesFor(string $type): iterable
  77. {
  78. yield [
  79. sprintf('<?php $b= (%s)$d;', $type),
  80. sprintf('<?php $b= (%s)$d;', strtoupper($type)),
  81. ];
  82. yield [
  83. sprintf('<?php $b=( %s) $d;', $type),
  84. sprintf('<?php $b=( %s) $d;', ucfirst($type)),
  85. ];
  86. yield [
  87. sprintf('<?php $b=(%s ) $d;', $type),
  88. sprintf('<?php $b=(%s ) $d;', strtoupper($type)),
  89. ];
  90. yield [
  91. sprintf('<?php $b=( %s ) $d;', $type),
  92. sprintf('<?php $b=( %s ) $d;', ucfirst($type)),
  93. ];
  94. }
  95. }