IntegrationCase.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Test;
  12. use PhpCsFixer\RuleSet;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. *
  16. * @internal
  17. */
  18. final class IntegrationCase
  19. {
  20. /**
  21. * @var array
  22. */
  23. private $config;
  24. /**
  25. * @var string
  26. */
  27. private $expectedCode;
  28. /**
  29. * @var string
  30. */
  31. private $fileName;
  32. /**
  33. * @var null|string
  34. */
  35. private $inputCode;
  36. /**
  37. * Env requirements (possible keys: php, hhvm).
  38. *
  39. * @var array
  40. */
  41. private $requirements;
  42. /**
  43. * @var RuleSet
  44. */
  45. private $ruleset;
  46. /**
  47. * Settings how to perform the test (possible keys: none in base class, use as extension point for custom IntegrationTestCase).
  48. *
  49. * @var array
  50. */
  51. private $settings;
  52. /**
  53. * @var string
  54. */
  55. private $title;
  56. /**
  57. * @param string $fileName
  58. * @param string $title
  59. * @param array $settings
  60. * @param array $requirements
  61. * @param array $config
  62. * @param RuleSet $ruleset
  63. * @param string $expectedCode
  64. * @param null|string $inputCode
  65. */
  66. public function __construct(
  67. $fileName,
  68. $title,
  69. array $settings,
  70. array $requirements,
  71. array $config,
  72. RuleSet $ruleset,
  73. $expectedCode,
  74. $inputCode
  75. ) {
  76. $this->fileName = $fileName;
  77. $this->title = $title;
  78. $this->settings = $settings;
  79. $this->requirements = $requirements;
  80. $this->config = $config;
  81. $this->ruleset = $ruleset;
  82. $this->expectedCode = $expectedCode;
  83. $this->inputCode = $inputCode;
  84. }
  85. public function hasInputCode()
  86. {
  87. return null !== $this->inputCode;
  88. }
  89. public function getConfig()
  90. {
  91. return $this->config;
  92. }
  93. public function getExpectedCode()
  94. {
  95. return $this->expectedCode;
  96. }
  97. public function getFileName()
  98. {
  99. return $this->fileName;
  100. }
  101. public function getInputCode()
  102. {
  103. return $this->inputCode;
  104. }
  105. /**
  106. * @param string $name
  107. *
  108. * @return mixed
  109. */
  110. public function getRequirement($name)
  111. {
  112. if (!is_string($name)) {
  113. throw new \InvalidArgumentException(sprintf(
  114. 'Requirement key must be a string, got "%s".',
  115. is_object($name) ? get_class($name) : gettype($name).'#'.$name
  116. ));
  117. }
  118. if (!array_key_exists($name, $this->requirements)) {
  119. throw new \InvalidArgumentException(sprintf(
  120. 'Unknown requirement key "%s", expected any of "%s".',
  121. $name,
  122. implode('","', array_keys($this->requirements))
  123. ));
  124. }
  125. return $this->requirements[$name];
  126. }
  127. public function getRequirements()
  128. {
  129. return $this->requirements;
  130. }
  131. public function getRuleset()
  132. {
  133. return $this->ruleset;
  134. }
  135. public function getSettings()
  136. {
  137. return $this->settings;
  138. }
  139. public function getTitle()
  140. {
  141. return $this->title;
  142. }
  143. }