LowercaseCastFixerTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\CastNotation;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author SpacePossum
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer
  19. */
  20. final class LowercaseCastFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideFixCases
  27. * @dataProvider provideFixDeprecatedCases
  28. * @requires PHP < 7.4
  29. */
  30. public function testFix($expected, $input = null)
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @param string $expected
  36. * @param null|string $input
  37. *
  38. * @dataProvider provideFixCases
  39. * @requires PHP 7.4
  40. */
  41. public function testFix74($expected, $input = null)
  42. {
  43. $this->doTest($expected, $input);
  44. }
  45. /**
  46. * @param string $expected
  47. * @param null|string $input
  48. *
  49. * @dataProvider provideFixDeprecatedCases
  50. * @requires PHP 7.4
  51. * @group legacy
  52. * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead
  53. * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead
  54. * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead
  55. * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead
  56. * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead
  57. */
  58. public function testFix74Deprecated($expected, $input = null)
  59. {
  60. $this->doTest($expected, $input);
  61. }
  62. public function provideFixCases()
  63. {
  64. foreach (['boolean', 'bool', 'integer', 'int', 'double', 'float', 'float', 'string', 'array', 'object', 'unset', 'binary'] as $from) {
  65. foreach ($this->createCasesFor($from) as $case) {
  66. yield $case;
  67. }
  68. }
  69. }
  70. public function provideFixDeprecatedCases()
  71. {
  72. return $this->createCasesFor('real');
  73. }
  74. private function createCasesFor($type)
  75. {
  76. yield [
  77. sprintf('<?php $b= (%s)$d;', $type),
  78. sprintf('<?php $b= (%s)$d;', strtoupper($type)),
  79. ];
  80. yield [
  81. sprintf('<?php $b=( %s) $d;', $type),
  82. sprintf('<?php $b=( %s) $d;', ucfirst($type)),
  83. ];
  84. yield [
  85. sprintf('<?php $b=(%s ) $d;', $type),
  86. sprintf('<?php $b=(%s ) $d;', strtoupper($type)),
  87. ];
  88. yield [
  89. sprintf('<?php $b=( %s ) $d;', $type),
  90. sprintf('<?php $b=( %s ) $d;', ucfirst($type)),
  91. ];
  92. }
  93. }