LowercaseCastFixerTest.php 2.9 KB

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