Example #1
0
 public function testResolve()
 {
     $this->profiler->start('foo', 'barbar');
     $this->profiler->stop('foo');
     $this->profiler->monitor('Foobar', function () {
         // yeah
     });
     $this->assertInstanceOf(\Generator::class, $this->datasource->getProcess($this->process->getId()));
 }
Example #2
0
 protected function setUp()
 {
     parent::setUp();
     $this->datasource = new Memory();
     $profiler = new Profiler();
     $profiler->setDataSource($this->datasource);
     $this->process = $profiler->getContext()->getProcess();
     $this->collector = new Request($this->process, $profiler->getDatasource());
     $profiler->registerCollector($this->collector);
 }
Example #3
0
 public function testResolveMonolog()
 {
     $monolog = new Monolog();
     $log = new Logger('name');
     $log->pushHandler($monolog);
     $monolog->setDispatcher($this->process->getDispatcher());
     $this->profiler->setLogger($monolog);
     $log->addError('Bar');
     $this->profiler->alert('FooBar');
     $this->assertInstanceOf(\Generator::class, $this->datasource->getProcess($this->process->getId()));
 }
Example #4
0
 /**
  * @param array $options
  * @return Profiler
  *
  * @throws \RuntimeException
  * @throws AccessException
  * @throws UndefinedOptionsException
  * @throws MissingOptionsException
  * @throws InvalidOptionsException
  * @throws NoSuchOptionException
  * @throws OptionDefinitionException
  */
 public function create(array $options = [])
 {
     $options = $this->resolveOptions($options);
     if (!$options[self::OPTION_ENABLE]) {
         return new NullProfiler();
     }
     if ($options[self::OPTION_ENVIRONMENT] !== null) {
         Profiler::$environment = $options[self::OPTION_ENVIRONMENT];
     }
     $profiler = new Profiler();
     switch ($options[self::OPTION_DATASOURCE_CLASS]) {
         default:
         case File::class:
             $datasource = new File($options[self::OPTION_DATASOURCE_PROFILES_FOLDER]);
             break;
         case Memory::class:
             $datasource = new Memory();
     }
     $profiler->setDataSource($datasource);
     $profiler->registerCollectorClasses($options[self::OPTION_COLLECTORS]);
     $dispatcher = $profiler->getContext()->getProcess()->getDispatcher();
     $className = $options['logger'];
     $logger = new $className();
     $logger->setDispatcher($dispatcher);
     $profiler->setLogger($logger);
     $profiler->setTimeline(new TimelineComponent($dispatcher));
     return $profiler;
 }
Example #5
0
 public function testContext()
 {
     Profiler::$environment = 'http';
     $this->profiler = ProfilerFactory::build([]);
     $this->assertInstanceOf(ContextInterface::class, $this->profiler->getContext());
     $this->assertInstanceOf(Http::class, $this->profiler->getContext());
     $this->profiler->getContext()->sendDebugIds();
 }
Example #6
0
 public function testTerminateFileDatasource()
 {
     $folder = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
     $this->profiler->setDataSource(new File($folder));
     $this->profiler->registerCollectorClasses([Duration::class, Request::class, Http::class]);
     $this->profiler->initiate();
     $this->profiler->terminate();
     $process = $this->profiler->getContext()->getProcess();
     $this->assertInstanceOf(\Generator::class, $this->profiler->getDatasource()->getProcess($process->getId()));
     $profile = $this->profiler->getProfile($process->getId());
     $this->assertObjectHasAttribute('duration', $profile);
 }