ScenarioNode.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /*
  3. * This file is part of the Behat Gherkin.
  4. * (c) Konstantin Kudryashov <ever.zet@gmail.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Behat\Gherkin\Node;
  10. /**
  11. * Represents Gherkin Scenario.
  12. *
  13. * @author Konstantin Kudryashov <ever.zet@gmail.com>
  14. */
  15. class ScenarioNode implements ScenarioInterface
  16. {
  17. /**
  18. * @var string
  19. */
  20. private $title;
  21. /**
  22. * @var array
  23. */
  24. private $tags = array();
  25. /**
  26. * @var StepNode[]
  27. */
  28. private $steps = array();
  29. /**
  30. * @var string
  31. */
  32. private $keyword;
  33. /**
  34. * @var integer
  35. */
  36. private $line;
  37. /**
  38. * Initializes scenario.
  39. *
  40. * @param null|string $title
  41. * @param array $tags
  42. * @param StepNode[] $steps
  43. * @param string $keyword
  44. * @param integer $line
  45. */
  46. public function __construct($title, array $tags, array $steps, $keyword, $line)
  47. {
  48. $this->title = $title;
  49. $this->tags = $tags;
  50. $this->steps = $steps;
  51. $this->keyword = $keyword;
  52. $this->line = $line;
  53. }
  54. /**
  55. * Returns node type string
  56. *
  57. * @return string
  58. */
  59. public function getNodeType()
  60. {
  61. return 'Scenario';
  62. }
  63. /**
  64. * Returns scenario title.
  65. *
  66. * @return null|string
  67. */
  68. public function getTitle()
  69. {
  70. return $this->title;
  71. }
  72. /**
  73. * Checks if scenario is tagged with tag.
  74. *
  75. * @param string $tag
  76. *
  77. * @return Boolean
  78. */
  79. public function hasTag($tag)
  80. {
  81. return in_array($tag, $this->getTags());
  82. }
  83. /**
  84. * Checks if scenario has tags (both inherited from feature and own).
  85. *
  86. * @return Boolean
  87. */
  88. public function hasTags()
  89. {
  90. return 0 < count($this->getTags());
  91. }
  92. /**
  93. * Returns scenario tags (including inherited from feature).
  94. *
  95. * @return array
  96. */
  97. public function getTags()
  98. {
  99. return $this->tags;
  100. }
  101. /**
  102. * Checks if scenario has steps.
  103. *
  104. * @return Boolean
  105. */
  106. public function hasSteps()
  107. {
  108. return 0 < count($this->steps);
  109. }
  110. /**
  111. * Returns scenario steps.
  112. *
  113. * @return StepNode[]
  114. */
  115. public function getSteps()
  116. {
  117. return $this->steps;
  118. }
  119. /**
  120. * Returns scenario keyword.
  121. *
  122. * @return string
  123. */
  124. public function getKeyword()
  125. {
  126. return $this->keyword;
  127. }
  128. /**
  129. * Returns scenario declaration line number.
  130. *
  131. * @return integer
  132. */
  133. public function getLine()
  134. {
  135. return $this->line;
  136. }
  137. }