IntegrationCase.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. private $config;
  21. /**
  22. * @var string
  23. */
  24. private $expectedCode;
  25. /**
  26. * @var string
  27. */
  28. private $fileName;
  29. /**
  30. * @var null|string
  31. */
  32. private $inputCode;
  33. /**
  34. * Env requirements (possible keys: php).
  35. *
  36. * @var array
  37. */
  38. private $requirements;
  39. /**
  40. * @var RuleSet
  41. */
  42. private $ruleset;
  43. /**
  44. * Settings how to perform the test (possible keys: none in base class, use as extension point for custom IntegrationTestCase).
  45. *
  46. * @var array
  47. */
  48. private $settings;
  49. /**
  50. * @var string
  51. */
  52. private $title;
  53. /**
  54. * @param string $fileName
  55. * @param string $title
  56. * @param array $settings
  57. * @param array $requirements
  58. * @param array $config
  59. * @param RuleSet $ruleset
  60. * @param string $expectedCode
  61. * @param null|string $inputCode
  62. */
  63. public function __construct(
  64. $fileName,
  65. $title,
  66. array $settings,
  67. array $requirements,
  68. array $config,
  69. RuleSet $ruleset,
  70. $expectedCode,
  71. $inputCode
  72. ) {
  73. $this->fileName = $fileName;
  74. $this->title = $title;
  75. $this->settings = $settings;
  76. $this->requirements = $requirements;
  77. $this->config = $config;
  78. $this->ruleset = $ruleset;
  79. $this->expectedCode = $expectedCode;
  80. $this->inputCode = $inputCode;
  81. }
  82. public function hasInputCode()
  83. {
  84. return null !== $this->inputCode;
  85. }
  86. public function getConfig()
  87. {
  88. return $this->config;
  89. }
  90. public function getExpectedCode()
  91. {
  92. return $this->expectedCode;
  93. }
  94. public function getFileName()
  95. {
  96. return $this->fileName;
  97. }
  98. public function getInputCode()
  99. {
  100. return $this->inputCode;
  101. }
  102. /**
  103. * @param string $name
  104. *
  105. * @return mixed
  106. */
  107. public function getRequirement($name)
  108. {
  109. if (!is_string($name)) {
  110. throw new \InvalidArgumentException(sprintf(
  111. 'Requirement key must be a string, got "%s".',
  112. is_object($name) ? get_class($name) : gettype($name).'#'.$name
  113. ));
  114. }
  115. if (!array_key_exists($name, $this->requirements)) {
  116. throw new \InvalidArgumentException(sprintf(
  117. 'Unknown requirement key "%s", expected any of "%s".',
  118. $name,
  119. implode('","', array_keys($this->requirements))
  120. ));
  121. }
  122. return $this->requirements[$name];
  123. }
  124. public function getRequirements()
  125. {
  126. return $this->requirements;
  127. }
  128. public function getRuleset()
  129. {
  130. return $this->ruleset;
  131. }
  132. public function getSettings()
  133. {
  134. return $this->settings;
  135. }
  136. public function getTitle()
  137. {
  138. return $this->title;
  139. }
  140. }