PhpBench\Benchmark\Metadata\BenchmarkMetadata::setBeforeClassMethods PHP Method

setBeforeClassMethods() public method

Set any methods that should be called before the benchmark class is executed.
public setBeforeClassMethods ( array $beforeClassMethods )
$beforeClassMethods array
    public function setBeforeClassMethods(array $beforeClassMethods)
    {
        $this->beforeClassMethods = $beforeClassMethods;
    }

Usage Example

 private function buildBenchmarkMetadata(BenchmarkMetadata $classMetadata, ReflectionHierarchy $hierarchy)
 {
     $annotations = array();
     $reflectionHierarchy = array_reverse(iterator_to_array($hierarchy));
     foreach ($reflectionHierarchy as $reflection) {
         $benchAnnotations = $this->docParser->parse($reflection->comment, sprintf('benchmark %s', $reflection->class));
         $annotations = array_merge($annotations, $benchAnnotations);
         foreach ($benchAnnotations as $annotation) {
             if ($annotation instanceof BeforeClassMethods) {
                 $classMetadata->setBeforeClassMethods($annotation->getMethods());
             }
             if ($annotation instanceof AfterClassMethods) {
                 $classMetadata->setAfterClassMethods($annotation->getMethods());
             }
             $this->processAbstractMetadata($classMetadata, $annotation);
         }
     }
     foreach ($reflectionHierarchy as $reflection) {
         foreach ($reflection->methods as $reflectionMethod) {
             if ('bench' !== substr($reflectionMethod->name, 0, 5)) {
                 continue;
             }
             $subjectMetadata = $classMetadata->getOrCreateSubjectMetadata($reflectionMethod->name);
             // apply the benchmark annotations to the subject
             foreach ($annotations as $annotation) {
                 $this->processAbstractMetadata($subjectMetadata, $annotation);
             }
             $this->buildSubjectMetadata($subjectMetadata, $reflectionMethod);
             $classMetadata->setSubjectMetadata($subjectMetadata);
         }
     }
 }
All Usage Examples Of PhpBench\Benchmark\Metadata\BenchmarkMetadata::setBeforeClassMethods