TagComparatorTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\DocBlock;
  13. use PhpCsFixer\DocBlock\Line;
  14. use PhpCsFixer\DocBlock\Tag;
  15. use PhpCsFixer\DocBlock\TagComparator;
  16. use PhpCsFixer\Tests\TestCase;
  17. /**
  18. * @author Graham Campbell <hello@gjcampbell.co.uk>
  19. * @author Jakub Kwaśniewski <jakub@zero-85.pl>
  20. *
  21. * @internal
  22. *
  23. * @covers \PhpCsFixer\DocBlock\TagComparator
  24. */
  25. final class TagComparatorTest extends TestCase
  26. {
  27. /**
  28. * @dataProvider provideComparatorTogetherCases
  29. *
  30. * @group legacy
  31. */
  32. public function testComparatorTogether(string $first, string $second, bool $expected): void
  33. {
  34. $tag1 = new Tag(new Line('* @'.$first));
  35. $tag2 = new Tag(new Line('* @'.$second));
  36. $this->expectDeprecation('%AMethod PhpCsFixer\DocBlock\TagComparator::shouldBeTogether is deprecated and will be removed in version 4.0.');
  37. self::assertSame($expected, TagComparator::shouldBeTogether($tag1, $tag2));
  38. }
  39. public static function provideComparatorTogetherCases(): iterable
  40. {
  41. yield ['return', 'return', true];
  42. yield ['param', 'param', true];
  43. yield ['return', 'param', false];
  44. yield ['var', 'foo', false];
  45. yield ['api', 'deprecated', false];
  46. yield ['author', 'copyright', true];
  47. yield ['author', 'since', false];
  48. yield ['link', 'see', true];
  49. yield ['category', 'package', true];
  50. }
  51. /**
  52. * @dataProvider provideComparatorTogetherWithDefinedGroupsCases
  53. *
  54. * @param string[][] $groups
  55. *
  56. * @group legacy
  57. */
  58. public function testComparatorTogetherWithDefinedGroups(array $groups, string $first, string $second, bool $expected): void
  59. {
  60. $tag1 = new Tag(new Line('* @'.$first));
  61. $tag2 = new Tag(new Line('* @'.$second));
  62. $this->expectDeprecation('%AMethod PhpCsFixer\DocBlock\TagComparator::shouldBeTogether is deprecated and will be removed in version 4.0.');
  63. self::assertSame(
  64. $expected,
  65. TagComparator::shouldBeTogether($tag1, $tag2, $groups)
  66. );
  67. }
  68. public static function provideComparatorTogetherWithDefinedGroupsCases(): iterable
  69. {
  70. yield [[['param', 'return']], 'return', 'return', true];
  71. yield [[], 'param', 'return', false];
  72. yield [[['param', 'return']], 'return', 'param', true];
  73. yield [[['param', 'return']], 'var', 'foo', false];
  74. yield [[['param', 'return']], 'api', 'deprecated', false];
  75. yield [[['param', 'return']], 'author', 'copyright', false];
  76. yield [[['param', 'return'], ['author', 'since']], 'author', 'since', true];
  77. yield [[...TagComparator::DEFAULT_GROUPS, ['param', 'return']], 'link', 'see', true];
  78. yield [[['param', 'return']], 'category', 'package', false];
  79. }
  80. }