Esempio n. 1
0
 /**
  * @param bool $hasLogger
  * @param bool $hasCron
  * @dataProvider debugDataProvider
  */
 public function testDebug($hasLogger, $hasCron = false)
 {
     $doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $definitionName = 'test_definition';
     $definition = new ProcessDefinition();
     $definition->setName($definitionName);
     $triggerCron = '* * * * *';
     $triggerEvent = ProcessTrigger::EVENT_UPDATE;
     $trigger = new ProcessTrigger();
     $trigger->setDefinition($definition);
     if ($hasCron) {
         $trigger->setCron($triggerCron);
     } else {
         $trigger->setEvent($triggerEvent);
     }
     $entity = new \stdClass();
     $entityId = 1;
     if ($hasCron) {
         $data = new ProcessData();
     } else {
         $data = new ProcessData(array('data' => $entity));
     }
     $message = 'Test debug message';
     if ($hasCron) {
         $context = array('definition' => $definitionName, 'cron' => $triggerCron);
     } else {
         $context = array('definition' => $definitionName, 'event' => $triggerEvent, 'entityId' => $entityId);
     }
     if ($hasLogger) {
         if ($hasCron) {
             $doctrineHelper->expects($this->never())->method('getSingleEntityIdentifier');
         } else {
             $doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity, false)->will($this->returnValue($entityId));
         }
         $logger = $this->getMock('Psr\\Log\\LoggerInterface');
         $logger->expects($this->once())->method('debug')->with($message, $context);
     } else {
         $doctrineHelper->expects($this->never())->method('getSingleEntityIdentifier');
         $logger = null;
     }
     $processLogger = new ProcessLogger($doctrineHelper, $logger);
     $processLogger->debug($message, $trigger, $data);
 }