WordMatcherTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 list<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. /**
  34. * @return iterable<array{?string, string, list<string>}>
  35. */
  36. public static function provideMatchCases(): iterable
  37. {
  38. yield [
  39. null,
  40. 'foo',
  41. [
  42. 'no_blank_lines_after_class_opening',
  43. 'no_blank_lines_after_phpdoc',
  44. ],
  45. ];
  46. yield [
  47. 'no_blank_lines_after_phpdoc',
  48. 'no_blank_lines_after_phpdocs',
  49. [
  50. 'no_blank_lines_after_class_opening',
  51. 'no_blank_lines_after_phpdoc',
  52. ],
  53. ];
  54. yield [
  55. 'no_blank_lines_after_foo',
  56. 'no_blank_lines_foo',
  57. [
  58. 'no_blank_lines_after_foo',
  59. 'no_blank_lines_before_foo',
  60. ],
  61. ];
  62. yield [
  63. null,
  64. 'braces',
  65. [
  66. 'elseif',
  67. ],
  68. ];
  69. }
  70. }