ObjectOperatorWithoutWhitespaceFixerTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\Operator;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Farhad Safarov <farhad.safarov@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer>
  22. */
  23. final class ObjectOperatorWithoutWhitespaceFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. '<?php $object->method();',
  39. '<?php $object ->method();',
  40. ];
  41. yield [
  42. '<?php $object->method();',
  43. '<?php $object -> method();',
  44. ];
  45. yield [
  46. '<?php $object->method();',
  47. '<?php $object-> method();',
  48. ];
  49. yield [
  50. '<?php $object->method();',
  51. '<?php $object ->method();',
  52. ];
  53. yield [
  54. '<?php $object->method();',
  55. '<?php $object-> method();',
  56. ];
  57. yield [
  58. '<?php $object->method();',
  59. '<?php $object -> method();',
  60. ];
  61. yield [
  62. '<?php echo "use it as -> you want";',
  63. ];
  64. // Ensure that doesn't break chained multi-line statements
  65. yield [
  66. '<?php $object->method()
  67. ->method2()
  68. ->method3();',
  69. ];
  70. yield [
  71. '<?php $this
  72. ->add()
  73. // Some comment
  74. ->delete();',
  75. ];
  76. }
  77. /**
  78. * @dataProvider provideFix80Cases
  79. *
  80. * @requires PHP 8.0
  81. */
  82. public function testFix80(string $expected, string $input): void
  83. {
  84. $this->doTest($expected, $input);
  85. }
  86. /**
  87. * @return iterable<array{string, string}>
  88. */
  89. public static function provideFix80Cases(): iterable
  90. {
  91. yield [
  92. '<?php $object?->method();',
  93. '<?php $object?-> method();',
  94. ];
  95. yield [
  96. '<?php $object?->method();',
  97. '<?php $object ?-> method();',
  98. ];
  99. }
  100. }