3 namespace Tests\Behat\Gherkin\Loader;
5 use Behat\Gherkin\Keywords\CucumberKeywords;
6 use Behat\Gherkin\Lexer;
7 use Behat\Gherkin\Loader\GherkinFileLoader;
8 use Behat\Gherkin\Parser;
10 class GherkinFileLoaderTest extends \PHPUnit_Framework_TestCase
13 * @var GherkinFileLoader
16 private $featuresPath;
18 public function testSupports()
20 $this->assertFalse($this->loader->supports('non-existent path'));
21 $this->assertFalse($this->loader->supports('non-existent path:2'));
23 $this->assertFalse($this->loader->supports(__DIR__));
24 $this->assertFalse($this->loader->supports(__DIR__ . ':d'));
25 $this->assertFalse($this->loader->supports(__FILE__));
26 $this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/features/pystring.feature'));
29 public function testLoad()
31 $features = $this->loader->load($this->featuresPath . '/pystring.feature');
32 $this->assertEquals(1, count($features));
33 $this->assertEquals('A py string feature', $features[0]->getTitle());
34 $this->assertEquals($this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', $features[0]->getFile());
36 $features = $this->loader->load($this->featuresPath . '/multiline_name.feature');
37 $this->assertEquals(1, count($features));
38 $this->assertEquals('multiline', $features[0]->getTitle());
39 $this->assertEquals($this->featuresPath . DIRECTORY_SEPARATOR . 'multiline_name.feature', $features[0]->getFile());
42 public function testParsingUncachedFeature()
44 $cache = $this->getMockBuilder('Behat\Gherkin\Cache\CacheInterface')->getMock();
45 $this->loader->setCache($cache);
47 $cache->expects($this->once())
49 ->with($path = $this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', filemtime($path))
50 ->will($this->returnValue(false));
52 $cache->expects($this->once())
55 $features = $this->loader->load($this->featuresPath . '/pystring.feature');
56 $this->assertEquals(1, count($features));
59 public function testParsingCachedFeature()
61 $cache = $this->getMockBuilder('Behat\Gherkin\Cache\CacheInterface')->getMock();
62 $this->loader->setCache($cache);
64 $cache->expects($this->once())
66 ->with($path = $this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', filemtime($path))
67 ->will($this->returnValue(true));
69 $cache->expects($this->once())
72 ->will($this->returnValue('cache'));
74 $cache->expects($this->never())
77 $features = $this->loader->load($this->featuresPath . '/pystring.feature');
78 $this->assertEquals('cache', $features[0]);
81 public function testBasePath()
83 $this->assertFalse($this->loader->supports('features'));
84 $this->assertFalse($this->loader->supports('tables.feature'));
86 $this->loader->setBasePath($this->featuresPath . '/../');
87 $this->assertFalse($this->loader->supports('features'));
88 $this->assertFalse($this->loader->supports('tables.feature'));
89 $this->assertTrue($this->loader->supports('features/tables.feature'));
91 $features = $this->loader->load('features/pystring.feature');
92 $this->assertEquals(1, count($features));
93 $this->assertEquals('A py string feature', $features[0]->getTitle());
94 $this->assertEquals('features' . DIRECTORY_SEPARATOR . 'pystring.feature', $features[0]->getFile());
96 $this->loader->setBasePath($this->featuresPath);
97 $features = $this->loader->load('multiline_name.feature');
98 $this->assertEquals(1, count($features));
99 $this->assertEquals('multiline', $features[0]->getTitle());
100 $this->assertEquals('multiline_name.feature', $features[0]->getFile());
103 protected function setUp()
105 $keywords = new CucumberKeywords(__DIR__ . '/../Fixtures/i18n.yml');
106 $parser = new Parser(new Lexer($keywords));
107 $this->loader = new GherkinFileLoader($parser);
109 $this->featuresPath = realpath(__DIR__ . '/../Fixtures/features');