TagComparatorTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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('Method PhpCsFixer\DocBlock\TagComparator::shouldBeTogether is deprecated and will be removed in version 4.0.');
  37. self::assertSame($expected, TagComparator::shouldBeTogether($tag1, $tag2));
  38. }
  39. /**
  40. * @return iterable<array{string, string, bool}>
  41. */
  42. public static function provideComparatorTogetherCases(): iterable
  43. {
  44. yield ['return', 'return', true];
  45. yield ['param', 'param', true];
  46. yield ['return', 'param', false];
  47. yield ['var', 'foo', false];
  48. yield ['api', 'deprecated', false];
  49. yield ['author', 'copyright', true];
  50. yield ['author', 'since', false];
  51. yield ['link', 'see', true];
  52. yield ['category', 'package', true];
  53. }
  54. /**
  55. * @dataProvider provideComparatorTogetherWithDefinedGroupsCases
  56. *
  57. * @param list<list<string>> $groups
  58. *
  59. * @group legacy
  60. */
  61. public function testComparatorTogetherWithDefinedGroups(array $groups, string $first, string $second, bool $expected): void
  62. {
  63. $tag1 = new Tag(new Line('* @'.$first));
  64. $tag2 = new Tag(new Line('* @'.$second));
  65. $this->expectDeprecation('Method PhpCsFixer\DocBlock\TagComparator::shouldBeTogether is deprecated and will be removed in version 4.0.');
  66. self::assertSame(
  67. $expected,
  68. TagComparator::shouldBeTogether($tag1, $tag2, $groups)
  69. );
  70. }
  71. public static function provideComparatorTogetherWithDefinedGroupsCases(): iterable
  72. {
  73. yield [[['param', 'return']], 'return', 'return', true];
  74. yield [[], 'param', 'return', false];
  75. yield [[['param', 'return']], 'return', 'param', true];
  76. yield [[['param', 'return']], 'var', 'foo', false];
  77. yield [[['param', 'return']], 'api', 'deprecated', false];
  78. yield [[['param', 'return']], 'author', 'copyright', false];
  79. yield [[['param', 'return'], ['author', 'since']], 'author', 'since', true];
  80. yield [[...TagComparator::DEFAULT_GROUPS, ['param', 'return']], 'link', 'see', true];
  81. yield [[['param', 'return']], 'category', 'package', false];
  82. }
  83. }