IntegrationCase.php 3.5 KB

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