Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function create(JobInterface $job)
 {
     $level = $this->registry->get($job->getType())->getLogLevel();
     if (false === $level) {
         return new NullLogger();
     } elseif (null === $level) {
         $level = $this->level;
     }
     $handlers = $this->handlerFactory->createHandlers($job, $level, $this->bubble);
     return new Logger($this->buildChannel($job), array_merge($handlers, $this->handlers));
 }
 /**
  * @param int     $level
  * @param boolean $bubble
  * @dataProvider provideLevels
  */
 public function testCreateHandlers($level, $bubble)
 {
     $job = new Job();
     $factory1 = $this->createMock(HandlerFactoryInterface::class);
     $handler1 = $this->createMock(HandlerInterface::class);
     $factory2 = $this->createMock(HandlerFactoryInterface::class);
     $handler2 = $this->createMock(HandlerInterface::class);
     $factory1->expects($this->once())->method('createHandler')->with($job, $level, $bubble)->willReturn($handler1);
     $factory2->expects($this->once())->method('createHandler')->with($job, $level, $bubble)->willReturn($handler2);
     $this->subject->register($factory1);
     $this->subject->register($factory2);
     $handlers = $this->subject->createHandlers($job, $level, $bubble);
     $this->assertContains($handler1, $handlers);
     $this->assertContains($handler2, $handlers);
 }
Exemplo n.º 3
0
 public function testCreatesLoggerWithAddedHandlers()
 {
     $job = new Job();
     $job->setType('JobType');
     $handler = $this->createMock(HandlerInterface::class);
     $extraHandler = $this->createMock(HandlerInterface::class);
     $factory = $this->getMockBuilder(BaseHandlerFactory::class)->disableOriginalConstructor()->getMock();
     $jobType = $this->createMock(JobTypeInterface::class);
     $this->handlerFactory->register($factory);
     $jobType->expects($this->any())->method('getLogLevel')->willReturn(Logger::CRITICAL);
     $this->registry->expects($this->once())->method('get')->with($job->getType())->willReturn($jobType);
     $factory->expects($this->once())->method('createHandler')->willReturn($handler);
     $this->subject->addHandler($extraHandler);
     $logger = $this->subject->create($job);
     $this->assertContains($handler, $logger->getHandlers());
     $this->assertContains($extraHandler, $logger->getHandlers());
 }