Behat\Gherkin\Gherkin::load PHP Method

load() public method

Loads & filters resource with added loaders.
public load ( mixed $resource, array $filters = [] ) : array
$resource mixed Resource to load
$filters array Additional filters
return array
    public function load($resource, array $filters = array())
    {
        $filters = array_merge($this->filters, $filters);
        $matches = array();
        if (preg_match('/^(.*)\\:(\\d+)-(\\d+|\\*)$/', $resource, $matches)) {
            $resource = $matches[1];
            $filters[] = new LineRangeFilter($matches[2], $matches[3]);
        } elseif (preg_match('/^(.*)\\:(\\d+)$/', $resource, $matches)) {
            $resource = $matches[1];
            $filters[] = new LineFilter($matches[2]);
        }
        $loader = $this->resolveLoader($resource);
        if (null === $loader) {
            return array();
        }
        $features = array();
        foreach ($loader->load($resource) as $feature) {
            foreach ($filters as $filter) {
                $feature = $filter->filterFeature($feature);
                if (!$feature->hasScenarios() && !$filter->isFeatureMatch($feature)) {
                    continue 2;
                }
            }
            $features[] = $feature;
        }
        return $features;
    }

Usage Example

 public function testLoaderFiltersFeatures()
 {
     $gherkin = new Gherkin();
     $gherkin->addLoader($loader = $this->getLoaderMock());
     $gherkin->addFilter($nameFilter = $this->getNameFilterMock());
     $feature = new FeatureNode();
     $loader->expects($this->once())->method('supports')->with($resource = 'some/feature/resource')->will($this->returnValue(true));
     $loader->expects($this->once())->method('load')->with($resource)->will($this->returnValue(array($feature)));
     $nameFilter->expects($this->once())->method('filterFeature')->with($this->identicalTo($feature));
     $nameFilter->expects($this->once())->method('isFeatureMatch')->with($this->identicalTo($feature))->will($this->returnValue(false));
     $features = $gherkin->load($resource);
     $this->assertEquals(0, count($features));
 }
All Usage Examples Of Behat\Gherkin\Gherkin::load