Exemplo n.º 1
0
 public function getMetadataForHierarchy(ReflectionHierarchy $hierarchy)
 {
     $primaryReflection = $hierarchy->getTop();
     $benchmark = new BenchmarkMetadata($primaryReflection->path, $primaryReflection->class);
     $this->buildBenchmark($benchmark, $hierarchy);
     return $benchmark;
 }
Exemplo n.º 2
0
 private function validateMethodExists($context, ReflectionHierarchy $benchmarkReflection, $method, $isStatic = false)
 {
     if (false === $benchmarkReflection->hasMethod($method)) {
         throw new \InvalidArgumentException(sprintf('Unknown %s method "%s" in benchmark class "%s"', $context, $method, $benchmarkReflection->getTop()->class));
     }
     if ($isStatic !== $benchmarkReflection->hasStaticMethod($method)) {
         throw new \InvalidArgumentException(sprintf('%s method "%s" must be static in benchmark class "%s"', $context, $method, $benchmarkReflection->getTop()->class));
     }
 }
Exemplo n.º 3
0
    /**
     * It should throw a helpful exception when an annotation is not recognized.
     *
     * @expectedException InvalidArgumentException
     * @expectedExceptionMessage Unrecognized annotation @Foobar, valid PHPBench annotations: @BeforeMethods,
     */
    public function testUsefulException()
    {
        $hierarchy = 'test';
        $reflection = new ReflectionClass();
        $reflection->class = 'TestChild';
        $reflection->comment = <<<EOT
    /**
     * @Foobar("foo")
     */
EOT;
        $hierarchy = new ReflectionHierarchy();
        $hierarchy->addReflectionClass($reflection);
        $this->driver->getMetadataForHierarchy($hierarchy);
    }
Exemplo n.º 4
0
 /**
  * It should allow a custom subject pattern.
  */
 public function testCustomSubjectPattern()
 {
     $reflection = new ReflectionClass();
     $reflection->class = 'Test';
     $method = new ReflectionMethod();
     $method->reflectionClass = $reflection;
     $method->class = 'Test';
     $method->name = 'foo_bar_Foo';
     $reflection->methods[$method->name] = $method;
     $hierarchy = new ReflectionHierarchy();
     $hierarchy->addReflectionClass($reflection);
     $metadata = $this->createDriver('foo_bar_')->getMetadataForHierarchy($hierarchy);
     $this->assertCount(1, $metadata->getSubjects());
     $this->assertArrayHasKey('foo_bar_Foo', $metadata->getSubjects());
 }