DirectoryLoaderTest.php 2.9 KB

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