| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Tests\Behat\Gherkin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Behat\Gherkin\Gherkin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Behat\Gherkin\Node\FeatureNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Behat\Gherkin\Node\ScenarioNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class GherkinTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function testLoader() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $customFilter1 = $this->getCustomFilterMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $customFilter2 = $this->getCustomFilterMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $gherkin = new Gherkin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $gherkin->addLoader($loader = $this->getLoaderMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $gherkin->addFilter($nameFilter = $this->getNameFilterMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $gherkin->addFilter($tagFilter = $this->getTagFilterMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $scenario = new ScenarioNode(null, array(), array(), null, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $feature = new FeatureNode(null, null, array(), null, array($scenario), null, null, null, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             ->method('supports') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             ->with($resource = 'some/feature/resource') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             ->will($this->returnValue(true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ->method('load') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ->with($resource) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ->will($this->returnValue(array($feature))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $nameFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ->method('filterFeature') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ->with($this->identicalTo($feature)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             ->will($this->returnValue($feature)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $tagFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ->method('filterFeature') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->with($this->identicalTo($feature)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ->will($this->returnValue($feature)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $customFilter1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ->method('filterFeature') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ->with($this->identicalTo($feature)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ->will($this->returnValue($feature)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $customFilter2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             ->method('filterFeature') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->with($this->identicalTo($feature)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ->will($this->returnValue($feature)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $features = $gherkin->load($resource, array($customFilter1, $customFilter2)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->assertEquals(1, count($features)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $scenarios = $features[0]->getScenarios(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->assertEquals(1, count($scenarios)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->assertSame($scenario, $scenarios[0]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function testNotFoundLoader() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $gherkin = new Gherkin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertEquals(array(), $gherkin->load('some/feature/resource')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function testLoaderFiltersFeatures() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $gherkin = new Gherkin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $gherkin->addLoader($loader = $this->getLoaderMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $gherkin->addFilter($nameFilter = $this->getNameFilterMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ->method('supports') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ->with($resource = 'some/feature/resource') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ->will($this->returnValue(true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             ->method('load') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ->with($resource) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ->will($this->returnValue(array($feature))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $nameFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             ->method('filterFeature') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             ->with($this->identicalTo($feature)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             ->will($this->returnValue($feature)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $nameFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             ->method('isFeatureMatch') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             ->with($this->identicalTo($feature)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             ->will($this->returnValue(false)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $features = $gherkin->load($resource); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $this->assertEquals(0, count($features)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     public function testSetFiltersOverridesAllFilters() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $gherkin = new Gherkin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $gherkin->addLoader($loader = $this->getLoaderMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $gherkin->addFilter($nameFilter = $this->getNameFilterMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $gherkin->setFilters(array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             ->method('supports') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             ->with($resource = 'some/feature/resource') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             ->will($this->returnValue(true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             ->method('load') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             ->with($resource) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             ->will($this->returnValue(array($feature))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $nameFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             ->expects($this->never()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             ->method('filterFeature'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $nameFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             ->expects($this->never()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             ->method('isFeatureMatch'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $features = $gherkin->load($resource); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $this->assertEquals(1, count($features)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     public function testSetBasePath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $gherkin = new Gherkin(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $gherkin->addLoader($loader1 = $this->getLoaderMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $gherkin->addLoader($loader2 = $this->getLoaderMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $loader1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             ->method('setBasePath') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             ->with($basePath = '/base/path') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             ->will($this->returnValue(null)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $loader2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             ->method('setBasePath') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             ->with($basePath = '/base/path') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             ->will($this->returnValue(null)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $gherkin->setBasePath($basePath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     protected function getLoaderMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         return $this->getMockBuilder('Behat\Gherkin\Loader\GherkinFileLoader') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |     protected function getCustomFilterMock() | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |         return $this->getMockBuilder('Behat\Gherkin\Filter\FilterInterface') | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     protected function getNameFilterMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         return $this->getMockBuilder('Behat\Gherkin\Filter\NameFilter') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     protected function getTagFilterMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         return $this->getMockBuilder('Behat\Gherkin\Filter\TagFilter') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 185 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 186 |  |  |  |