3 namespace Tests\Behat\Gherkin\Loader;
5 use Behat\Gherkin\Loader\DirectoryLoader;
7 class DirectoryLoaderTest extends \PHPUnit_Framework_TestCase
11 private $featuresPath;
13 protected function setUp()
15 $this->gherkin = $this->createGherkinMock();
16 $this->loader = new DirectoryLoader($this->gherkin);
18 $this->featuresPath = realpath(__DIR__ . '/../Fixtures/directories');
21 protected function createGherkinMock()
23 $gherkin = $this->getMockBuilder('Behat\Gherkin\Gherkin')
24 ->disableOriginalConstructor()
30 protected function createGherkinFileLoaderMock()
32 $loader = $this->getMockBuilder('Behat\Gherkin\Loader\GherkinFileLoader')
33 ->disableOriginalConstructor()
39 public function testSupports()
41 $this->assertFalse($this->loader->supports('non-existent path'));
42 $this->assertFalse($this->loader->supports('non-existent path:2'));
44 $this->assertFalse($this->loader->supports(__DIR__ . ':d'));
45 $this->assertFalse($this->loader->supports(__DIR__ . '/../Fixtures/features/pystring.feature'));
46 $this->assertTrue($this->loader->supports(__DIR__));
47 $this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/features'));
50 public function testUndefinedFileLoad()
53 ->expects($this->once())
54 ->method('resolveLoader')
55 ->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php')
56 ->will($this->returnValue(null));
58 $this->assertEquals(array(), $this->loader->load($this->featuresPath . '/phps'));
61 public function testBasePath()
64 ->expects($this->once())
65 ->method('resolveLoader')
66 ->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php')
67 ->will($this->returnValue(null));
69 $this->loader->setBasePath($this->featuresPath);
71 $this->assertEquals(array(), $this->loader->load('phps'));
74 public function testDefinedFileLoad()
76 $loaderMock = $this->createGherkinFileLoaderMock();
79 ->expects($this->once())
80 ->method('resolveLoader')
81 ->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php')
82 ->will($this->returnValue($loaderMock));
85 ->expects($this->once())
87 ->with($this->featuresPath.DIRECTORY_SEPARATOR.'phps'.DIRECTORY_SEPARATOR.'some_file.php')
88 ->will($this->returnValue(array('feature1', 'feature2')));
90 $this->assertEquals(array('feature1', 'feature2'), $this->loader->load($this->featuresPath . '/phps'));