public function benchStoreParams() { $uuid = uniqid(); $collection = TestUtil::createCollection([['uuid' => $uuid . 'a', 'parameters' => ['one' => 'two', 'three' => 'four', 'two' => 'five', '7' => 'eight'], 'env' => ['foo' => ['foo' => 'bar', 'bar' => 'foo'], 'bar' => ['foo' => 'bar', 'bar' => 'foo'], 'baz' => ['foo' => 'bar', 'bar' => 'foo'], 'bog' => ['foo' => 'bar', 'bar' => 'foo']]], ['uuid' => $uuid . 'b'], ['uuid' => $uuid . 'c'], ['uuid' => $uuid . 'd']]); $this->driver->store($collection); $uuid++; }
/** * It should generate an environment report for each suite. */ public function testEnvEachSuite() { $collection = TestUtil::createCollection([['env' => ['vcs' => ['branch' => 'my_branch']]], ['env' => ['vcs' => ['branch' => 'my_branch']]]]); $report = $this->generator->generate($collection, new Config('foo', [])); $this->assertXPathCount($report, 1, '//table[contains(@title, "Suite #0")]'); $this->assertXPathCount($report, 1, '//table[contains(@title, "Suite #1")]'); }
/** * It should delete a specified run and all of its relations. */ public function testDelete() { $suiteCollection = new SuiteCollection([TestUtil::createSuite(['uuid' => 1234, 'subjects' => ['one', 'two'], 'env' => ['system' => ['os' => 'linux', 'distribution' => 'debian']]])]); $this->persister->persist($suiteCollection); $counts = $this->getTableCounts(); $this->assertEquals(['run' => 1, 'subject' => 2, 'variant' => 2, 'parameter' => 1, 'variant_parameter' => 2, 'sgroup_subject' => 6, 'environment' => 2, 'iteration' => 4, 'version' => 1], $counts); $this->repository->deleteRun(1234); $counts = $this->getTableCounts(); $this->assertEquals(['run' => 0, 'subject' => 2, 'variant' => 0, 'parameter' => 1, 'variant_parameter' => 0, 'sgroup_subject' => 6, 'environment' => 0, 'iteration' => 0, 'version' => 1], $counts); }
/** * The PHPBench version should be stored in the database. */ public function testPhpBenchVersion() { $suiteCollection = new SuiteCollection([TestUtil::createSuite(['uuid' => 1])]); $this->persister->persist($suiteCollection); $rows = $this->sqlQuery('SELECT * FROM version'); $this->assertCount(1, $rows); $row = current($rows); $this->assertEquals(PhpBench::VERSION, $row['phpbench_version']); $suiteCollection = new SuiteCollection([TestUtil::createSuite(['uuid' => 2])]); $this->persister->persist($suiteCollection); $this->assertEquals(1, $this->sqlCount('SELECT * FROM version')); }
/** * It should iterate over the history. */ public function testHistoryStatement() { $suiteCollection = new SuiteCollection([TestUtil::createSuite(['uuid' => 1, 'env' => ['vcs' => ['system' => 'git', 'branch' => 'branch_1']], 'name' => 'one', 'date' => '2016-01-01']), TestUtil::createSuite(['uuid' => 2, 'date' => '2015-01-01', 'env' => ['vcs' => ['system' => 'git', 'branch' => 'branch_2']], 'name' => 'two'])]); $this->persister->persist($suiteCollection); $current = $this->iterator->current(); $this->assertInstanceOf('PhpBench\\Storage\\HistoryEntry', $current); $this->assertEquals('2016-01-01', $current->getDate()->format('Y-m-d')); $this->assertEquals('branch_1', $current->getVcsBranch()); $this->assertEquals('one', $current->getContext()); $this->assertEquals(1, $current->getRunId()); $this->iterator->next(); $current = $this->iterator->current(); $this->assertInstanceOf('PhpBench\\Storage\\HistoryEntry', $current); $this->assertEquals('2015-01-01', $current->getDate()->format('Y-m-d')); $this->assertEquals('branch_2', $current->getVcsBranch()); $this->assertEquals('two', $current->getContext()); $this->assertEquals(2, $current->getRunId()); }
/** * It should show statistics when an iteration is completed (and there * were no rejections). */ public function testIterationEndStats() { foreach ($this->variant as $iteration) { foreach (TestUtil::createResults(10, 10) as $result) { $iteration->setResult($result); } } $this->variant->computeStats(); $this->logger->variantEnd($this->variant); $this->assertContains('RSD/r: 0.00%', $this->output->fetch()); }
/** * 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__)); }
/** * 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->getSubjects()->willReturn([$this->subjectMetadata->reveal()]); TestUtil::configureBenchmarkMetadata($this->metadata, ['class' => 'TestBench', 'path' => self::PATH]); TestUtil::configureSubjectMetadata($this->subjectMetadata, ['name' => 'benchTest']); $this->reflector->getParameterSets(self::PATH, [])->willReturn(['asd' => 'bar']); $this->factory->getMetadataForFile(self::FNAME); }
/** * 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 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 return the revolution time. */ public function testGetRevTime() { $iteration = new Iteration(1, $this->variant->reveal(), TestUtil::createResults(100)); $this->variant->getRevolutions()->willReturn(100); $this->assertEquals(1, $iteration->getResult(TimeResult::class)->getRevTime(100)); }
/** * It should show the histogram and statistics when an iteration is * completed (and there were no rejections). */ public function testIterationEnd() { foreach ($this->variant as $iteration) { foreach (TestUtil::createResults(10, 10) as $result) { $iteration->setResult($result); } } $this->variant->computeStats(); $this->logger->variantEnd($this->variant); $display = $this->output->fetch(); $this->assertContains('1 (σ = 0.000ms ) -2σ [ █ ] +2σ [μ Mo]/r: 0.010 0.010 μRSD/r: 0.00%', $display); }
/** * It should add environmental information to the DOM. */ public function testEnvironment() { $this->informations['hello'] = new Information('hello', ['say' => 'goodbye']); $subject = new SubjectMetadata($this->benchmark->reveal(), 'name', 0); $this->benchmark->getSubjects()->willReturn([$subject]); TestUtil::configureBenchmarkMetadata($this->benchmark); $this->executor->execute(Argument::type('PhpBench\\Benchmark\\Metadata\\SubjectMetadata'), Argument::type('PhpBench\\Model\\Iteration'), $this->executorConfig)->shouldBeCalledTimes(1)->will($this->loadIterationResultCallback()); $suite = $this->runner->run(new RunnerContext(__DIR__)); $envInformations = $suite->getEnvInformations(); $this->assertSame((array) $this->informations, (array) $envInformations); }
/** * It should return times and memories. */ public function testGetMetricValues() { $variant = new Variant($this->subject->reveal(), $this->parameterSet->reveal(), 1, 0); $variant->createIteration(TestUtil::createResults(4, 100)); $variant->createIteration(TestUtil::createResults(8, 200)); $times = $variant->getMetricValuesByRev(TimeResult::class, 'net'); $memories = $variant->getMetricValues(MemoryResult::class, 'peak'); $this->assertEquals([4, 8], $times); $this->assertEquals([100, 200], $memories); }
/** * It should filer by groups. */ public function testFilterGroups() { $suiteCollection = new SuiteCollection([TestUtil::createSuite(['uuid' => '1', 'benchmark' => ['benchOne'], 'subjects' => ['benchOne'], 'groups' => ['one', 'two']]), TestUtil::createSuite(['uuid' => '2', 'benchmark' => ['benchOne'], 'subjects' => ['benchTwo', 'benchThree'], 'groups' => ['foobar']])]); $this->persister->persist($suiteCollection); $suiteCollection = $this->loader->load(new Comparison('$eq', 'group', 'one')); $suite = $suiteCollection->getIterator()->current(); $this->assertNotNull($suite); $this->assertCount(1, $suite->getSubjects()); $suiteCollection = $this->loader->load(new Comparison('$eq', 'group', 'two')); $suite = $suiteCollection->getIterator()->current(); $this->assertCount(1, $suite->getSubjects()); $suiteCollection = $this->loader->load(new Comparison('$eq', 'group', 'foobar')); $suite = $suiteCollection->getIterator()->current(); $this->assertCount(2, $suite->getSubjects()); }
/** * It should customize the column names by column index. */ public function testCustomizeColumnLabelsIndex() { $report = $this->generate(TestUtil::createCollection([[]]), ['labels' => ['Column one', 'Column two', 'params' => 'Parameters']]); $this->assertXPathCount($report, 14, '//col'); $this->assertXPathEval($report, 'Column one', 'string(//table/cols/col[1]/@label)'); $this->assertXPathEval($report, 'Column two', 'string(//table/cols/col[2]/@label)'); $this->assertXPathEval($report, 'groups', 'string(//table/cols/col[3]/@label)'); $this->assertXPathEval($report, 'Parameters', 'string(//table/cols/col[4]/@label)'); }