ExplicitIndirectVariableFixerTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\LanguageConstruct;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Filippo Tessarotto <zoeslam@gmail.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer
  19. */
  20. final class ExplicitIndirectVariableFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideTestFixCases
  27. * @requires PHP 7.0
  28. */
  29. public function testFix($expected, $input = null)
  30. {
  31. $this->doTest($expected, $input);
  32. }
  33. public function provideTestFixCases()
  34. {
  35. return [
  36. [
  37. '<?php echo ${$foo}($bar);',
  38. '<?php echo $$foo($bar);',
  39. ],
  40. [
  41. '<?php echo ${$foo}[\'bar\'][\'baz\'];',
  42. '<?php echo $$foo[\'bar\'][\'baz\'];',
  43. ],
  44. [
  45. '<?php echo $foo->{$bar}[\'baz\'];',
  46. '<?php echo $foo->$bar[\'baz\'];',
  47. ],
  48. [
  49. '<?php echo $foo->{$bar}[\'baz\']();',
  50. '<?php echo $foo->$bar[\'baz\']();',
  51. ],
  52. [
  53. '<?php echo $
  54. /* C1 */
  55. // C2
  56. {$foo}
  57. // C3
  58. ;',
  59. '<?php echo $
  60. /* C1 */
  61. // C2
  62. $foo
  63. // C3
  64. ;',
  65. ],
  66. ];
  67. }
  68. }