public function testSimple() { $this->expectOutputString("onFinish\nonFinish"); $item = new Item(); $item->attach($this); $manager = new Manager(new Item('N')); $this->assertSame('N', $manager->getPrototype()->getTitle()); $this->assertSame($manager, $manager->setPrototype($item)); $this->assertSame($item, $manager->getPrototype()); $this->assertInstanceOf(\SplQueue::class, $manager->getIterator()); $this->assertNull($manager->top()); foreach ($manager as $item) { $this->fail('Should be empty iteration now: ' . gettype($item)); } $newItem = $manager->create('1'); $this->assertInstanceOf(Item::class, $newItem); $this->assertSame('1', $newItem->getTitle()); $this->assertNotSame($item, $newItem); $this->assertSame($newItem, $manager->start()); $this->assertInstanceOf(StateRunning::class, $newItem->getState()); $this->assertInstanceOf(StatePaused::class, $manager->pause()->getState()); $this->assertSame($newItem, $manager->top()); $this->assertInstanceOf(StateRunning::class, $manager->resume()->getState()); $newItem->stop(); $this->assertNull($manager->discard()); echo "\n"; $this->assertNotSame($newItem, $newItem2 = $manager->namedStart('2')); $this->assertCount(1, $manager); $this->assertSame('2', $newItem2->getTitle()); $this->assertSame($newItem2, $manager->stop()); $this->assertCount(2, $manager); $item->detach($this); $this->assertSame('3', $manager->start()->setTitle('3')->setHandled(true)->stop()->getTitle()); $this->assertCount(2, $manager); }
public function testInClosure() { $finish = function (Item $item) { $trace = $item->stop()->refScopeStatistic(BacktraceObserver::class); $this->assertSame('PHProfilingTest\\Example\\BacktraceTest->testInClosure', $trace[BacktraceObserver::FILED_START_POSITION][BacktraceObserver::SUB_FILED_EXPRESSION]); $this->assertRegExp('/closure(\\$|\\})/i', $trace[BacktraceObserver::FILED_STOP_POSITION][BacktraceObserver::SUB_FILED_EXPRESSION]); }; $finish($this->manager->namedStart('3')); }
public function testTag() { $manager = new Manager(); $tag = new TaggingObserver('SQL'); $this->assertSame('SQL', $tag->getTag()); $manager->getPrototype()->attach($tag); $manager->namedStart('foo'); $item = $manager->stop(); $this->assertSame('foo', $item->getTitle()); $this->assertSame('SQL', $item->getStatistic(TaggingObserver::class, TaggingObserver::FILED_TAG)); }
public function testBasic() { $this->expectOutputRegex('/\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}] test\\.DEBUG: 1 \\{"PHProfiling\\\\\\\\Example\\\\\\\\TaggingObserver":\\{"tag":"EX"\\},"PHProfiling\\\\\\\\Example\\\\\\\\MemoryPeekUseObserver":\\{"usage":\\d+\\}\\} \\[\\]/'); $logger = new Logger('test'); $logger->pushHandler(new StreamHandler('php://output')); $prototype = new Item(); $prototype->attach(new MonologOutput($logger, Logger::DEBUG)); $prototype->attach(new TaggingObserver('EX')); $prototype->attach(new MemoryPeekUseObserver()); $manager = new Manager($prototype); $manager->namedStart('1'); $memoryEater = range(0, 500); $this->assertTrue($manager->stop()->isHandled()); unset($memoryEater); }
public function testTiming() { $this->manager->namedStart('test'); usleep(500000); $this->manager->pause(); usleep(750000); $this->manager->resume(); usleep(500000); $item = $this->manager->stop(); $this->assertEquals(1, $item->getStatistic(TimingObserver::class, TimingObserver::FILED_RUNTIME), 'Time is out of tolerance, check delta first.', 0.1); $this->manager->namedStart('test2'); usleep(300000); $this->manager->pause(); usleep(700000); $item = $this->manager->stop(); $this->assertEquals(0.3, $item->getStatistic(TimingObserver::class, TimingObserver::FILED_RUNTIME), 'Time is out of tolerance, check delta first.', 0.1); $this->assertEquals(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], TimingObserver::getGlobalT(), 'Global time is out of tolerance, check delta first.', 0.1); }