/** * It should serialize the retry threshold. */ public function testRetryThreshold() { $this->collection->getBenchmarks()->willReturn(array($this->benchmark)); 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'))->shouldBeCalledTimes(1)->willReturn(new IterationResult(10, 10)); $result = $this->runner->run(new RunnerContext(__DIR__, array('retry_threshold' => 10))); $this->assertInstanceOf('PhpBench\\Benchmark\\SuiteDocument', $result); $this->assertContains('retry-threshold="10"', $result->dump()); }
/** * 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)')); }
/** * 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); }
/** * 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); }