WordMatcherTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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;
  13. use PhpCsFixer\WordMatcher;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\WordMatcher
  20. */
  21. final class WordMatcherTest extends TestCase
  22. {
  23. /**
  24. * @param string[] $candidates
  25. *
  26. * @dataProvider provideMatchCases
  27. */
  28. public function testMatch(?string $expected, string $needle, array $candidates): void
  29. {
  30. $matcher = new WordMatcher($candidates);
  31. self::assertSame($expected, $matcher->match($needle));
  32. }
  33. public static function provideMatchCases(): iterable
  34. {
  35. yield [
  36. null,
  37. 'foo',
  38. [
  39. 'no_blank_lines_after_class_opening',
  40. 'no_blank_lines_after_phpdoc',
  41. ],
  42. ];
  43. yield [
  44. 'no_blank_lines_after_phpdoc',
  45. 'no_blank_lines_after_phpdocs',
  46. [
  47. 'no_blank_lines_after_class_opening',
  48. 'no_blank_lines_after_phpdoc',
  49. ],
  50. ];
  51. yield [
  52. 'no_blank_lines_after_foo',
  53. 'no_blank_lines_foo',
  54. [
  55. 'no_blank_lines_after_foo',
  56. 'no_blank_lines_before_foo',
  57. ],
  58. ];
  59. yield [
  60. null,
  61. 'braces',
  62. [
  63. 'elseif',
  64. ],
  65. ];
  66. }
  67. }