PRTypeLabelsTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\AutoReview;
  13. use PhpCsFixer\Preg;
  14. use PhpCsFixer\Tests\TestCase;
  15. use Symfony\Component\Yaml\Yaml;
  16. /**
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @coversNothing
  22. *
  23. * @group auto-review
  24. * @group covers-nothing
  25. */
  26. final class PRTypeLabelsTest extends TestCase
  27. {
  28. public function testTemplateTypesCoverPRLintTypes(): void
  29. {
  30. $templateTypes = $this->getTypesFromReleaseNotesTemplate();
  31. $prLintTypes = $this->getTypesFromPRLint();
  32. $expectedTypes = [
  33. ...$prLintTypes,
  34. '*',
  35. 'BC',
  36. 'deps',
  37. 'revert',
  38. ];
  39. sort($expectedTypes);
  40. self::assertSame($expectedTypes, $templateTypes);
  41. }
  42. /**
  43. * @return string[]
  44. */
  45. private function getTypesFromReleaseNotesTemplate(): array
  46. {
  47. $template = Yaml::parse(file_get_contents(__DIR__.'/../../.github/release.yml'));
  48. $types = array_merge(
  49. ...array_map(
  50. static fn (array $item): array => $item['labels'],
  51. $template['changelog']['categories']
  52. )
  53. );
  54. $types = array_map(
  55. static fn (string $item): string => str_replace('type/', '', $item),
  56. $types
  57. );
  58. sort($types);
  59. return $types;
  60. }
  61. /**
  62. * @return string[]
  63. */
  64. private function getTypesFromPRLint(): array
  65. {
  66. $prlint = json_decode(file_get_contents(__DIR__.'/../../.github/prlint.json'), true, 512, JSON_THROW_ON_ERROR);
  67. $typesPattern = $prlint['title'][0]['pattern'];
  68. Preg::match('/(?<=\()[^)]+(?=\))/', $typesPattern, $matches);
  69. $types = explode('|', $matches[0]);
  70. sort($types);
  71. return $types;
  72. }
  73. }