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
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class GherkinFileLoaderTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var GherkinFileLoader |
15
|
|
|
*/ |
16
|
|
|
private $loader; |
17
|
|
|
private $featuresPath; |
18
|
|
|
|
19
|
|
|
public function testSupports() |
20
|
|
|
{ |
21
|
|
|
$this->assertFalse($this->loader->supports('non-existent path')); |
22
|
|
|
$this->assertFalse($this->loader->supports('non-existent path:2')); |
23
|
|
|
|
24
|
|
|
$this->assertFalse($this->loader->supports(__DIR__)); |
25
|
|
|
$this->assertFalse($this->loader->supports(__DIR__ . ':d')); |
26
|
|
|
$this->assertFalse($this->loader->supports(__FILE__)); |
27
|
|
|
$this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/features/pystring.feature')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testLoad() |
31
|
|
|
{ |
32
|
|
|
$features = $this->loader->load($this->featuresPath . '/pystring.feature'); |
33
|
|
|
$this->assertEquals(1, count($features)); |
34
|
|
|
$this->assertEquals('A py string feature', $features[0]->getTitle()); |
35
|
|
|
$this->assertEquals($this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', $features[0]->getFile()); |
36
|
|
|
|
37
|
|
|
$features = $this->loader->load($this->featuresPath . '/multiline_name.feature'); |
38
|
|
|
$this->assertEquals(1, count($features)); |
39
|
|
|
$this->assertEquals('multiline', $features[0]->getTitle()); |
40
|
|
|
$this->assertEquals($this->featuresPath . DIRECTORY_SEPARATOR . 'multiline_name.feature', $features[0]->getFile()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testParsingUncachedFeature() |
44
|
|
|
{ |
45
|
|
|
$cache = $this->getMockBuilder('Behat\Gherkin\Cache\CacheInterface')->getMock(); |
46
|
|
|
$this->loader->setCache($cache); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$cache->expects($this->once()) |
49
|
|
|
->method('isFresh') |
50
|
|
|
->with($path = $this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', filemtime($path)) |
51
|
|
|
->will($this->returnValue(false)); |
52
|
|
|
|
53
|
|
|
$cache->expects($this->once()) |
54
|
|
|
->method('write'); |
55
|
|
|
|
56
|
|
|
$features = $this->loader->load($this->featuresPath . '/pystring.feature'); |
57
|
|
|
$this->assertEquals(1, count($features)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testParsingCachedFeature() |
61
|
|
|
{ |
62
|
|
|
$cache = $this->getMockBuilder('Behat\Gherkin\Cache\CacheInterface')->getMock(); |
63
|
|
|
$this->loader->setCache($cache); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$cache->expects($this->once()) |
66
|
|
|
->method('isFresh') |
67
|
|
|
->with($path = $this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature', filemtime($path)) |
68
|
|
|
->will($this->returnValue(true)); |
69
|
|
|
|
70
|
|
|
$cache->expects($this->once()) |
71
|
|
|
->method('read') |
72
|
|
|
->with($path) |
73
|
|
|
->will($this->returnValue('cache')); |
74
|
|
|
|
75
|
|
|
$cache->expects($this->never()) |
76
|
|
|
->method('write'); |
77
|
|
|
|
78
|
|
|
$features = $this->loader->load($this->featuresPath . '/pystring.feature'); |
79
|
|
|
$this->assertEquals('cache', $features[0]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testBasePath() |
83
|
|
|
{ |
84
|
|
|
$this->assertFalse($this->loader->supports('features')); |
85
|
|
|
$this->assertFalse($this->loader->supports('tables.feature')); |
86
|
|
|
|
87
|
|
|
$this->loader->setBasePath($this->featuresPath . '/../'); |
88
|
|
|
$this->assertFalse($this->loader->supports('features')); |
89
|
|
|
$this->assertFalse($this->loader->supports('tables.feature')); |
90
|
|
|
$this->assertTrue($this->loader->supports('features/tables.feature')); |
91
|
|
|
|
92
|
|
|
$features = $this->loader->load('features/pystring.feature'); |
93
|
|
|
$this->assertEquals(1, count($features)); |
94
|
|
|
$this->assertEquals('A py string feature', $features[0]->getTitle()); |
95
|
|
|
$this->assertEquals(realpath($this->featuresPath . DIRECTORY_SEPARATOR . 'pystring.feature'), $features[0]->getFile()); |
96
|
|
|
|
97
|
|
|
$this->loader->setBasePath($this->featuresPath); |
98
|
|
|
$features = $this->loader->load('multiline_name.feature'); |
99
|
|
|
$this->assertEquals(1, count($features)); |
100
|
|
|
$this->assertEquals('multiline', $features[0]->getTitle()); |
101
|
|
|
$this->assertEquals(realpath($this->featuresPath . DIRECTORY_SEPARATOR . 'multiline_name.feature'), $features[0]->getFile()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function setUp() |
105
|
|
|
{ |
106
|
|
|
$keywords = new CucumberKeywords(__DIR__ . '/../Fixtures/i18n.yml'); |
107
|
|
|
$parser = new Parser(new Lexer($keywords)); |
108
|
|
|
$this->loader = new GherkinFileLoader($parser); |
109
|
|
|
|
110
|
|
|
$this->featuresPath = realpath(__DIR__ . '/../Fixtures/features'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: