IntegrationCase.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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\Test;
  13. use PhpCsFixer\RuleSet\RuleSet;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. */
  19. final class IntegrationCase
  20. {
  21. /**
  22. * @var array{indent: string, lineEnding: string}
  23. */
  24. private array $config;
  25. private string $expectedCode;
  26. private string $fileName;
  27. private ?string $inputCode;
  28. /**
  29. * Env requirements (possible keys: 'php' or 'php<').
  30. *
  31. * @var array<string, int>|array{php: int}
  32. */
  33. private array $requirements;
  34. private RuleSet $ruleset;
  35. /**
  36. * Settings how to perform the test (possible keys: none in base class, use as extension point for custom IntegrationTestCase).
  37. *
  38. * @var array{checkPriority: bool, deprecations: list<string>, isExplicitPriorityCheck?: bool}
  39. */
  40. private array $settings;
  41. private string $title;
  42. /**
  43. * @param array{checkPriority: bool, deprecations: list<string>, isExplicitPriorityCheck?: bool} $settings
  44. * @param array<string, int>|array{php: int} $requirements
  45. * @param array{indent: string, lineEnding: string} $config
  46. */
  47. public function __construct(
  48. string $fileName,
  49. string $title,
  50. array $settings,
  51. array $requirements,
  52. array $config,
  53. RuleSet $ruleset,
  54. string $expectedCode,
  55. ?string $inputCode
  56. ) {
  57. $this->fileName = $fileName;
  58. $this->title = $title;
  59. $this->settings = $settings;
  60. $this->requirements = $requirements;
  61. $this->config = $config;
  62. $this->ruleset = $ruleset;
  63. $this->expectedCode = $expectedCode;
  64. $this->inputCode = $inputCode;
  65. }
  66. public function hasInputCode(): bool
  67. {
  68. return null !== $this->inputCode;
  69. }
  70. /**
  71. * @return array{indent: string, lineEnding: string}
  72. */
  73. public function getConfig(): array
  74. {
  75. return $this->config;
  76. }
  77. public function getExpectedCode(): string
  78. {
  79. return $this->expectedCode;
  80. }
  81. public function getFileName(): string
  82. {
  83. return $this->fileName;
  84. }
  85. public function getInputCode(): ?string
  86. {
  87. return $this->inputCode;
  88. }
  89. public function getRequirement(string $name): int
  90. {
  91. if (!\array_key_exists($name, $this->requirements)) {
  92. throw new \InvalidArgumentException(sprintf(
  93. 'Unknown requirement key "%s", expected any of "%s".',
  94. $name,
  95. implode('","', array_keys($this->requirements))
  96. ));
  97. }
  98. return $this->requirements[$name];
  99. }
  100. /**
  101. * @return array<string, int>|array{php: int}
  102. */
  103. public function getRequirements(): array
  104. {
  105. return $this->requirements;
  106. }
  107. public function getRuleset(): RuleSet
  108. {
  109. return $this->ruleset;
  110. }
  111. /**
  112. * @return array{checkPriority: bool, deprecations: list<string>, isExplicitPriorityCheck?: bool}
  113. */
  114. public function getSettings(): array
  115. {
  116. return $this->settings;
  117. }
  118. public function getTitle(): string
  119. {
  120. return $this->title;
  121. }
  122. }