|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Gherkin\Loader\DirectoryLoader; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class DirectoryLoaderTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
private $gherkin; |
|
11
|
|
|
private $loader; |
|
12
|
|
|
private $featuresPath; |
|
13
|
|
|
|
|
14
|
|
|
protected function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->gherkin = $this->createGherkinMock(); |
|
17
|
|
|
$this->loader = new DirectoryLoader($this->gherkin); |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
$this->featuresPath = realpath(__DIR__ . '/../Fixtures/directories'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
protected function createGherkinMock() |
|
23
|
|
|
{ |
|
24
|
|
|
$gherkin = $this->getMockBuilder('Behat\Gherkin\Gherkin') |
|
25
|
|
|
->disableOriginalConstructor() |
|
26
|
|
|
->getMock(); |
|
27
|
|
|
|
|
28
|
|
|
return $gherkin; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function createGherkinFileLoaderMock() |
|
32
|
|
|
{ |
|
33
|
|
|
$loader = $this->getMockBuilder('Behat\Gherkin\Loader\GherkinFileLoader') |
|
34
|
|
|
->disableOriginalConstructor() |
|
35
|
|
|
->getMock(); |
|
36
|
|
|
|
|
37
|
|
|
return $loader; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testSupports() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertFalse($this->loader->supports('non-existent path')); |
|
43
|
|
|
$this->assertFalse($this->loader->supports('non-existent path:2')); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertFalse($this->loader->supports(__DIR__ . ':d')); |
|
46
|
|
|
$this->assertFalse($this->loader->supports(__DIR__ . '/../Fixtures/features/pystring.feature')); |
|
47
|
|
|
$this->assertTrue($this->loader->supports(__DIR__)); |
|
48
|
|
|
$this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/features')); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testUndefinedFileLoad() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->gherkin |
|
54
|
|
|
->expects($this->once()) |
|
55
|
|
|
->method('resolveLoader') |
|
56
|
|
|
->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php') |
|
57
|
|
|
->will($this->returnValue(null)); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertEquals(array(), $this->loader->load($this->featuresPath . '/phps')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testBasePath() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->gherkin |
|
65
|
|
|
->expects($this->once()) |
|
66
|
|
|
->method('resolveLoader') |
|
67
|
|
|
->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php') |
|
68
|
|
|
->will($this->returnValue(null)); |
|
69
|
|
|
|
|
70
|
|
|
$this->loader->setBasePath($this->featuresPath); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals(array(), $this->loader->load('phps')); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testDefinedFileLoad() |
|
76
|
|
|
{ |
|
77
|
|
|
$loaderMock = $this->createGherkinFileLoaderMock(); |
|
78
|
|
|
|
|
79
|
|
|
$this->gherkin |
|
80
|
|
|
->expects($this->once()) |
|
81
|
|
|
->method('resolveLoader') |
|
82
|
|
|
->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php') |
|
83
|
|
|
->will($this->returnValue($loaderMock)); |
|
84
|
|
|
|
|
85
|
|
|
$loaderMock |
|
86
|
|
|
->expects($this->once()) |
|
87
|
|
|
->method('load') |
|
88
|
|
|
->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php') |
|
89
|
|
|
->will($this->returnValue(array('feature1', 'feature2'))); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertEquals(array('feature1', 'feature2'), $this->loader->load($this->featuresPath . '/phps')); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
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: