Exemplo n.º 1
0
 public function testLogExecution()
 {
     $testExec = new Execution();
     $testExec->setAlias('def1')->setEnv($this->container->getParameter('kernel.environment'))->setExecutionTime(1)->setFailed(false)->setExecutionDatetime(new \DateTime());
     $this->entityManager->expects($this->once())->method('persist')->with($this->isInstanceOf(Execution::class))->willReturnCallback(function (Execution $execution) use($testExec) {
         $this->assertEquals($execution, $testExec);
     });
     $this->report->logExecution($testExec->getAlias(), $testExec->getExecutionTime(), $testExec->getExecutionDatetime(), $testExec->isFailed());
 }
Exemplo n.º 2
0
 /**
  * Logs a new cron execution.
  *
  * @param string $alias
  * @param float $executionTime
  * @param \DateTime $startTime
  * @param bool $failed
  *
  * @return Execution
  */
 public function logExecution($alias, $executionTime, \DateTime $startTime, $failed = false)
 {
     if (!array_key_exists($alias, $this->definitions)) {
         throw new \InvalidArgumentException('Unknown cron alias "' . $alias . '"');
     }
     $execution = new Execution();
     $execution->setAlias($alias)->setEnv($this->environment)->setExecutionTime($executionTime)->setExecutionDatetime($startTime)->setFailed($failed);
     $this->em->persist($execution);
     return $execution;
 }
 public function testCronFailed()
 {
     $container = $this->getContainer(['crons' => ['def1' => ['command' => 'babymarktext:test:command']]]);
     $reporter = new ExecutionReportListener(array_map(function ($def) {
         return new Definition($def);
     }, $container->getParameter('babymarkt_ext_cron.definitions')), $this->reporter);
     $reporter->onCronStart(new ConsoleCommandEvent($this->command, $this->input, $this->output));
     $reporter->onCronFinished(new ConsoleTerminateEvent($this->command, $this->input, $this->output, 1));
     $reporter->onCronFailed(new ConsoleExceptionEvent($this->command, $this->input, $this->output, new \Exception(), 1));
     $this->assertFalse($reporter->isSkipped());
     $this->assertTrue($this->execution->isFailed());
 }
 /**
  * @param ConsoleExceptionEvent $event
  */
 public function onCronFailed(ConsoleExceptionEvent $event)
 {
     if (!$this->skipped) {
         $this->execution->setFailed(true);
     }
 }