8f5d2c17d903bf18ab9513c1ef59e09889da93e9
[yaffs-website] / vendor / behat / gherkin / tests / Behat / Gherkin / Loader / GherkinFileLoaderTest.php
1 <?php
2
3 namespace Tests\Behat\Gherkin\Loader;
4
5 use Behat\Gherkin\Keywords\CucumberKeywords;
6 use Behat\Gherkin\Lexer;
7 use Behat\Gherkin\Loader\GherkinFileLoader;
8 use Behat\Gherkin\Parser;
9
10 class GherkinFileLoaderTest extends \PHPUnit_Framework_TestCase
11 {
12     /**
13      * @var GherkinFileLoader
14      */
15     private $loader;
16     private $featuresPath;
17
18     public function testSupports()
19     {
20         $this->assertFalse($this->loader->supports('non-existent path'));
21         $this->assertFalse($this->loader->supports('non-existent path:2'));
22
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'));
27     }
28
29     public function testLoad()
30     {
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());
35
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());
40     }
41
42     public function testParsingUncachedFeature()
43     {
44         $cache = $this->getMockBuilder('Behat\Gherkin\Cache\CacheInterface')->getMock();
45         $this->loader->setCache($cache);
46
47         $cache->expects($this->once())
48             ->method('isFresh')
49             ->with($path = $this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', filemtime($path))
50             ->will($this->returnValue(false));
51
52         $cache->expects($this->once())
53             ->method('write');
54
55         $features = $this->loader->load($this->featuresPath . '/pystring.feature');
56         $this->assertEquals(1, count($features));
57     }
58
59     public function testParsingCachedFeature()
60     {
61         $cache = $this->getMockBuilder('Behat\Gherkin\Cache\CacheInterface')->getMock();
62         $this->loader->setCache($cache);
63
64         $cache->expects($this->once())
65             ->method('isFresh')
66             ->with($path = $this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', filemtime($path))
67             ->will($this->returnValue(true));
68
69         $cache->expects($this->once())
70             ->method('read')
71             ->with($path)
72             ->will($this->returnValue('cache'));
73
74         $cache->expects($this->never())
75             ->method('write');
76
77         $features = $this->loader->load($this->featuresPath . '/pystring.feature');
78         $this->assertEquals('cache', $features[0]);
79     }
80
81     public function testBasePath()
82     {
83         $this->assertFalse($this->loader->supports('features'));
84         $this->assertFalse($this->loader->supports('tables.feature'));
85
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'));
90
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());
95
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());
101     }
102
103     protected function setUp()
104     {
105         $keywords = new CucumberKeywords(__DIR__ . '/../Fixtures/i18n.yml');
106         $parser = new Parser(new Lexer($keywords));
107         $this->loader = new GherkinFileLoader($parser);
108
109         $this->featuresPath = realpath(__DIR__ . '/../Fixtures/features');
110     }
111 }