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)); }
public function testSetFiltersOverridesAllFilters() { $gherkin = new Gherkin(); $gherkin->addLoader($loader = $this->getLoaderMock()); $gherkin->addFilter($nameFilter = $this->getNameFilterMock()); $gherkin->setFilters(array()); $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); $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->never())->method('filterFeature'); $nameFilter->expects($this->never())->method('isFeatureMatch'); $features = $gherkin->load($resource); $this->assertEquals(1, count($features)); }
protected function runFeatures(Gherkin $gherkin) { $features = array(); foreach ($this->getFeaturesPaths() as $path) { // parse every feature with Gherkin $features += $gherkin->load((string) $path); } $divider = new FeatureDivider($features); $divider->setPartsCount($this->countWorkers); $features = $divider->getFeaturesForPart($this->workerNumber); // and run it in FeatureTester foreach ($features as $feature) { $tester = $this->getContainer()->get('behat.tester.feature'); $tester->setSkip($this->isDryRun()); $feature->accept($tester); } }
public function testLoader() { $gherkin = new Gherkin(); $gherkin->addLoader($loader = $this->getLoaderMock()); $gherkin->addFilter($nameFilter = $this->getNameFilterMock()); $gherkin->addFilter($tagFilter = $this->getTagFilterMock()); $feature = new FeatureNode(); $feature->addScenario($scenario = new ScenarioNode()); $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('isScenarioMatch')->with($scenario)->will($this->returnValue(true)); $tagFilter->expects($this->once())->method('isScenarioMatch')->with($scenario)->will($this->returnValue(true)); $features = $gherkin->load($resource); $this->assertEquals(1, count($features)); $scenarios = $features[0]->getScenarios(); $this->assertEquals(1, count($scenarios)); $this->assertSame($scenario, $scenarios[0]); }
/** * Multiple features folders loader * * Delegates load execution to parent including filters management * * @param mixed $resource Resource to load * @param array $filters Additional filters * @return array */ public function load($resource, array $filters = array()) { // If a resource is specified don't overwrite the parent behaviour. if ($resource != '') { return parent::load($resource, $filters); } if (!is_array($this->moodleConfig)) { throw new RuntimeException('There are no Moodle features nor steps definitions'); } // Loads all the features files of each Moodle component. $features = array(); if (!empty($this->moodleConfig['features'])) { foreach ($this->moodleConfig['features'] as $path) { if (file_exists($path)) { $features = array_merge($features, parent::load($path, $filters)); } } } return $features; }
/** * Parses and runs provided features. * * @param Gherkin $gherkin gherkin parser/loader */ protected function runFeatures(Gherkin $gherkin) { foreach ($this->getFeaturesPaths() as $path) { // parse every feature with Gherkin $features = $gherkin->load((string) $path); // and run it in FeatureTester foreach ($features as $feature) { $tester = $this->getContainer()->get('behat.tester.feature'); $tester->setSkip($this->isDryRun()); $feature->accept($tester); } } }
/** * Parses feature at path. * * @param string $path * * @return FeatureNode[] */ private function parseFeature($path) { return $this->gherkin->load($path, $this->filters); }