YamlFileLoaderTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Tests\Behat\Gherkin\Loader;
  3. use Behat\Gherkin\Loader\YamlFileLoader;
  4. class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
  5. {
  6. private $loader;
  7. protected function setUp()
  8. {
  9. $this->loader = new YamlFileLoader();
  10. }
  11. public function testSupports()
  12. {
  13. $this->assertFalse($this->loader->supports(__DIR__));
  14. $this->assertFalse($this->loader->supports(__FILE__));
  15. $this->assertFalse($this->loader->supports('string'));
  16. $this->assertFalse($this->loader->supports(__DIR__ . '/file.yml'));
  17. $this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/etalons/addition.yml'));
  18. }
  19. public function testLoadAddition()
  20. {
  21. $this->loader->setBasePath(__DIR__ . '/../Fixtures');
  22. $features = $this->loader->load('etalons/addition.yml');
  23. $this->assertEquals(1, count($features));
  24. $this->assertEquals('etalons'.DIRECTORY_SEPARATOR.'addition.yml', $features[0]->getFile());
  25. $this->assertEquals('Addition', $features[0]->getTitle());
  26. $this->assertEquals(2, $features[0]->getLine());
  27. $this->assertEquals('en', $features[0]->getLanguage());
  28. $expectedDescription = <<<EOS
  29. In order to avoid silly mistakes
  30. As a math idiot
  31. I want to be told the sum of two numbers
  32. EOS;
  33. $this->assertEquals($expectedDescription, $features[0]->getDescription());
  34. $scenarios = $features[0]->getScenarios();
  35. $this->assertEquals(2, count($scenarios));
  36. $this->assertInstanceOf('Behat\Gherkin\Node\ScenarioNode', $scenarios[0]);
  37. $this->assertEquals(7, $scenarios[0]->getLine());
  38. $this->assertEquals('Add two numbers', $scenarios[0]->getTitle());
  39. $steps = $scenarios[0]->getSteps();
  40. $this->assertEquals(4, count($steps));
  41. $this->assertEquals(9, $steps[1]->getLine());
  42. $this->assertEquals('And', $steps[1]->getType());
  43. $this->assertEquals('And', $steps[1]->getKeyword());
  44. $this->assertEquals('Given', $steps[1]->getKeywordType());
  45. $this->assertEquals('I have entered 12 into the calculator', $steps[1]->getText());
  46. $this->assertInstanceOf('Behat\Gherkin\Node\ScenarioNode', $scenarios[1]);
  47. $this->assertEquals(13, $scenarios[1]->getLine());
  48. $this->assertEquals('Div two numbers', $scenarios[1]->getTitle());
  49. $steps = $scenarios[1]->getSteps();
  50. $this->assertEquals(4, count($steps));
  51. $this->assertEquals(16, $steps[2]->getLine());
  52. $this->assertEquals('When', $steps[2]->getType());
  53. $this->assertEquals('When', $steps[2]->getKeyword());
  54. $this->assertEquals('When', $steps[2]->getKeywordType());
  55. $this->assertEquals('I press div', $steps[2]->getText());
  56. }
  57. }