ParserExceptionsTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. namespace Tests\Behat\Gherkin;
  3. use Behat\Gherkin\Lexer;
  4. use Behat\Gherkin\Parser;
  5. use Behat\Gherkin\Keywords\ArrayKeywords;
  6. class ParserExceptionsTest extends \PHPUnit_Framework_TestCase
  7. {
  8. /**
  9. * @var Parser
  10. */
  11. private $gherkin;
  12. protected function setUp()
  13. {
  14. $keywords = new ArrayKeywords(array(
  15. 'en' => array(
  16. 'feature' => 'Feature',
  17. 'background' => 'Background',
  18. 'scenario' => 'Scenario',
  19. 'scenario_outline' => 'Scenario Outline',
  20. 'examples' => 'Examples',
  21. 'given' => 'Given',
  22. 'when' => 'When',
  23. 'then' => 'Then',
  24. 'and' => 'And',
  25. 'but' => 'But'
  26. ),
  27. 'ru' => array(
  28. 'feature' => 'Функционал',
  29. 'background' => 'Предыстория',
  30. 'scenario' => 'Сценарий',
  31. 'scenario_outline' => 'Структура сценария',
  32. 'examples' => 'Примеры',
  33. 'given' => 'Допустим',
  34. 'when' => 'То',
  35. 'then' => 'Если',
  36. 'and' => 'И',
  37. 'but' => 'Но'
  38. )
  39. ));
  40. $this->gherkin = new Parser(new Lexer($keywords));
  41. }
  42. public function testStepRightAfterFeature()
  43. {
  44. $feature = <<<GHERKIN
  45. Feature: Some feature
  46. Given some step-like line
  47. GHERKIN;
  48. $parsed = $this->gherkin->parse($feature);
  49. $this->assertEquals("\n Given some step-like line", $parsed->getDescription());
  50. }
  51. public function testTextInBackground()
  52. {
  53. $feature = <<<GHERKIN
  54. Feature: Behat bug test
  55. Background: remove X to couse bug
  56. Step is red form is not valid
  57. asd
  58. asd
  59. as
  60. da
  61. sd
  62. as
  63. das
  64. d
  65. Scenario: bug user edit date
  66. GHERKIN;
  67. $this->gherkin->parse($feature);
  68. }
  69. public function testTextInScenario()
  70. {
  71. $feature = <<<GHERKIN
  72. Feature: Behat bug test
  73. Scenario: remove X to cause bug
  74. Step is red form is not valid
  75. asd
  76. asd
  77. as
  78. da
  79. sd
  80. as
  81. das
  82. d
  83. Scenario Outline: bug user edit date
  84. Step is red form is not valid
  85. asd
  86. asd
  87. as
  88. da
  89. sd
  90. as
  91. das
  92. d
  93. Examples:
  94. ||
  95. GHERKIN;
  96. $feature = $this->gherkin->parse($feature);
  97. $this->assertCount(2, $scenarios = $feature->getScenarios());
  98. $firstTitle = <<<TEXT
  99. remove X to cause bug
  100. Step is red form is not valid
  101. asd
  102. asd
  103. as
  104. da
  105. sd
  106. as
  107. das
  108. d
  109. TEXT;
  110. $this->assertEquals($firstTitle, $scenarios[0]->getTitle());
  111. $secondTitle = <<<TEXT
  112. bug user edit date
  113. Step is red form is not valid
  114. asd
  115. asd
  116. as
  117. da
  118. sd
  119. as
  120. das
  121. d
  122. TEXT;
  123. $this->assertEquals($secondTitle, $scenarios[1]->getTitle());
  124. }
  125. /**
  126. * @expectedException \Behat\Gherkin\Exception\ParserException
  127. */
  128. public function testAmbigiousLanguage()
  129. {
  130. $feature = <<<GHERKIN
  131. # language: en
  132. # language: ru
  133. Feature: Some feature
  134. Given something wrong
  135. GHERKIN;
  136. $this->gherkin->parse($feature);
  137. }
  138. /**
  139. * @expectedException \Behat\Gherkin\Exception\ParserException
  140. */
  141. public function testEmptyOutline()
  142. {
  143. $feature = <<<GHERKIN
  144. Feature: Some feature
  145. Scenario Outline:
  146. GHERKIN;
  147. $this->gherkin->parse($feature);
  148. }
  149. /**
  150. * @expectedException \Behat\Gherkin\Exception\ParserException
  151. */
  152. public function testWrongTagPlacement()
  153. {
  154. $feature = <<<GHERKIN
  155. Feature: Some feature
  156. Scenario:
  157. Given some step
  158. @some_tag
  159. Then some additional step
  160. GHERKIN;
  161. $this->gherkin->parse($feature);
  162. }
  163. /**
  164. * @expectedException \Behat\Gherkin\Exception\ParserException
  165. */
  166. public function testBackgroundWithTag()
  167. {
  168. $feature = <<<GHERKIN
  169. Feature: Some feature
  170. @some_tag
  171. Background:
  172. Given some step
  173. GHERKIN;
  174. $this->gherkin->parse($feature);
  175. }
  176. /**
  177. * @expectedException \Behat\Gherkin\Exception\ParserException
  178. */
  179. public function testEndlessPyString()
  180. {
  181. $feature = <<<GHERKIN
  182. Feature:
  183. Scenario:
  184. Given something with:
  185. """
  186. some text
  187. GHERKIN;
  188. $this->gherkin->parse($feature);
  189. }
  190. /**
  191. * @expectedException \Behat\Gherkin\Exception\ParserException
  192. */
  193. public function testWrongStepType()
  194. {
  195. $feature = <<<GHERKIN
  196. Feature:
  197. Scenario:
  198. Given some step
  199. Aaand some step
  200. GHERKIN;
  201. $this->gherkin->parse($feature);
  202. }
  203. /**
  204. * @expectedException \Behat\Gherkin\Exception\ParserException
  205. */
  206. public function testMultipleBackgrounds()
  207. {
  208. $feature = <<<GHERKIN
  209. Feature:
  210. Background:
  211. Given some step
  212. Background:
  213. Aaand some step
  214. GHERKIN;
  215. $this->gherkin->parse($feature);
  216. }
  217. /**
  218. * @expectedException \Behat\Gherkin\Exception\ParserException
  219. */
  220. public function testMultipleFeatures()
  221. {
  222. $feature = <<<GHERKIN
  223. Feature:
  224. Feature:
  225. GHERKIN;
  226. $this->gherkin->parse($feature);
  227. }
  228. /**
  229. * @expectedException \Behat\Gherkin\Exception\ParserException
  230. */
  231. public function testTableWithoutRightBorder()
  232. {
  233. $feature = <<<GHERKIN
  234. Feature:
  235. Scenario:
  236. Given something with:
  237. | foo | bar
  238. | 42 | 42
  239. GHERKIN;
  240. $this->gherkin->parse($feature);
  241. }
  242. }