Esempio n. 1
0
 /**
  * It should call the before and after class methods.
  */
 public function testBeforeAndAfterClass()
 {
     TestUtil::configureBenchmark($this->benchmark, array('beforeClassMethods' => array('afterClass'), 'afterClassMethods' => array('beforeClass')));
     $this->executor->executeMethods($this->benchmark->reveal(), array('beforeClass'))->shouldBeCalled();
     $this->executor->executeMethods($this->benchmark->reveal(), array('afterClass'))->shouldBeCalled();
     $this->benchmark->getSubjectMetadatas()->willReturn(array());
     $this->collection->getBenchmarks()->willReturn(array($this->benchmark));
     $this->runner->run(new RunnerContext(__DIR__));
 }
Esempio n. 2
0
 /**
  * It should add environmental information to the DOM.
  */
 public function testEnvironment()
 {
     $this->informations[] = new Information('hello', array('say' => 'goodbye'));
     TestUtil::configureSubject($this->subject, array('sleep' => 50));
     $this->benchmark->getSubjectMetadatas()->willReturn(array($this->subject->reveal()));
     TestUtil::configureBenchmark($this->benchmark);
     $this->executor->execute(Argument::type('PhpBench\\Benchmark\\Iteration'), $this->executorConfig)->shouldBeCalledTimes(1)->willReturn(new IterationResult(10, 10));
     $result = $this->runner->run(new RunnerContext(__DIR__));
     $this->assertEquals(1, $result->evaluate('count(//env)'));
     $this->assertEquals('goodbye', $result->evaluate('string(//env/hello/@say)'));
 }
Esempio n. 3
0
 /**
  * It should handle exceptions thrown by the executor.
  * It should handle nested exceptions.
  */
 public function testHandleExceptions()
 {
     TestUtil::configureSubject($this->subject, array('sleep' => 50));
     $this->benchmark->getSubjectMetadatas()->willReturn(array($this->subject->reveal()));
     TestUtil::configureBenchmark($this->benchmark);
     $this->executor->execute(Argument::type('PhpBench\\Benchmark\\Iteration'), $this->executorConfig)->shouldBeCalledTimes(1)->willThrow(new \Exception('Foobar', null, new \InvalidArgumentException('Barfoo')));
     $result = $this->runner->run(new RunnerContext(__DIR__));
     $this->assertTrue($result->hasErrors());
     $this->assertTrue($result->evaluate('count(//error) = 2'));
     $this->assertEquals(1, $result->evaluate('count(//error[@exception-class="Exception"])'));
     $this->assertEquals(1, $result->evaluate('count(//error[@exception-class="InvalidArgumentException"])'));
     $nodes = $result->query('//error');
     $this->assertEquals('Foobar', $nodes->item(0)->nodeValue);
     $this->assertEquals('Barfoo', $nodes->item(1)->nodeValue);
 }
Esempio n. 4
0
 /**
  * It should throw an exception if the parameters are not in a valid format.
  *
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Each parameter set must be an array, got "string" for TestBench::benchTest
  */
 public function testInvalidParameters()
 {
     $this->hierarchy->isEmpty()->willReturn(false);
     $this->metadata->getSubjectMetadatas()->willReturn(array($this->subjectMetadata->reveal()));
     TestUtil::configureBenchmark($this->metadata, array('class' => 'TestBench', 'path' => self::PATH));
     TestUtil::configureSubject($this->subjectMetadata, array('name' => 'benchTest'));
     $this->reflector->getParameterSets(self::PATH, array())->willReturn(array('asd' => 'bar'));
     $this->factory->getMetadataForFile(self::FNAME);
 }