Esempio n. 1
0
 /**
  * Build the BenchmarkMetadata collection.
  *
  * @param string $path
  * @param array $subjectFilter
  * @param array $groupFilter
  */
 public function findBenchmarks($path, array $subjectFilter = [], array $groupFilter = [])
 {
     $finder = new Finder();
     $path = PhpBench::normalizePath($path);
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf('File or directory "%s" does not exist (cwd: %s)', $path, getcwd()));
     }
     if (is_dir($path)) {
         $finder->in($path)->name('*.php');
     } else {
         // the path is already a file, just restrict the finder to that.
         $finder->in(dirname($path))->depth(0)->name(basename($path));
     }
     $benchmarks = [];
     foreach ($finder as $file) {
         if (!is_file($file)) {
             continue;
         }
         $benchmark = $this->factory->getMetadataForFile($file->getPathname());
         if (null === $benchmark) {
             continue;
         }
         if ($groupFilter) {
             $benchmark->filterSubjectGroups($groupFilter);
         }
         if ($subjectFilter) {
             $benchmark->filterSubjectNames($subjectFilter);
         }
         if (false === $benchmark->hasSubjects()) {
             continue;
         }
         $benchmarks[] = $benchmark;
     }
     return $benchmarks;
 }
Esempio n. 2
0
 /**
  * Build the BenchmarkMetadata collection.
  *
  * @param string $path
  * @param array $subjectFilter
  * @param array $groupFilter
  */
 public function buildCollection($path, array $filters = array(), array $groupFilter = array())
 {
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf('File or directory "%s" does not exist (cwd: %s)', $path, getcwd()));
     }
     if (is_dir($path)) {
         $this->finder->in($path)->name('*Bench.php');
     } else {
         // the path is already a file, just restrict the finder to that.
         $this->finder->in(dirname($path))->depth(0)->name(basename($path));
     }
     $benchmarks = array();
     foreach ($this->finder as $file) {
         if (!is_file($file)) {
             continue;
         }
         $benchmarkMetadata = $this->factory->getMetadataForFile($file->getPathname());
         if (null === $benchmarkMetadata) {
             continue;
         }
         if ($groupFilter) {
             $benchmarkMetadata->filterSubjectGroups($groupFilter);
         }
         if ($filters) {
             $benchmarkMetadata->filterSubjectNames($filters);
         }
         if (false === $benchmarkMetadata->hasSubjects()) {
             continue;
         }
         $benchmarks[] = $benchmarkMetadata;
     }
     return new Collection($benchmarks);
 }