TagComparatorTest.php 3.0 KB

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