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