/** * Tests the constructor. * * @return void * * @covers \Windwalker\Profiler\Profiler::__construct * @since 2.0 */ public function test__construct() { $this->assertEquals('test', $this->instance->getName()); $this->assertInstanceOf('Windwalker\\Profiler\\Renderer\\DefaultRenderer', $this->instance->getRenderer()); $this->assertEmpty($this->instance->getPoints()); $this->assertEquals(PhpHelper::isHHVM(), $this->instance->getMemoryRealUsage()); $renderer = new DefaultRenderer(); $pointOne = new Point('start'); $pointTwo = new Point('two', 1, 1); $points = array('start' => $pointOne, 'two' => $pointTwo); $profiler = new Profiler('bar', $renderer, $points, false); $this->assertEquals('bar', $profiler->getName()); $this->assertSame($renderer, $profiler->getRenderer()); $this->assertEquals($points, $profiler->getPoints()); $this->assertFalse($profiler->getMemoryRealUsage()); }
/** * Constructor. * * @param string $name The profiler name. * @param ProfilerRendererInterface $renderer The renderer. * @param ProfilerPointInterface[] $points An array of profile points. * @param boolean $memoryRealUsage True to get the real memory usage. * * @throws \InvalidArgumentException */ public function __construct($name, ProfilerRendererInterface $renderer = null, array $points = array(), $memoryRealUsage = null) { $this->name = $name; $this->renderer = $renderer ?: new DefaultRenderer(); if (empty($points)) { $this->points = array(); } else { $this->setPoints($points); } // HHVM has different behavior on memory_get_usage() $this->memoryRealUsage = $memoryRealUsage === null ? PhpHelper::isHHVM() : (bool) $memoryRealUsage; }