Пример #1
0
 /**
  * @expectedException \Tebru\Executioner\Exception\FailedException
  */
 public function testWithLogger()
 {
     $callable = new MockeryCallableMock();
     $exception = new Exception();
     $callable->shouldBeCalled()->times(1)->withNoArgs()->andThrow($exception);
     $callable->shouldBeCalled()->times(1)->withNoArgs()->andReturn(true);
     $logger = Mockery::mock(LoggerInterface::class);
     $dispatchException = new Exception();
     $logger->shouldReceive('info')->times(1)->with('Attempting "test" with 1 attempts to go. (uq)');
     $logger->shouldReceive('info')->times(1)->with('Attempting "test" with 0 attempts to go. (uq)');
     $logger->shouldReceive('info')->times(1)->with('Completed attempt for "test" (uq)', ['result' => true])->andThrow($dispatchException);
     $logger->shouldReceive('notice')->times(1)->with('Failed attempt for "test", retrying. 0 attempts remaining (uq)', ['exception' => $exception]);
     $logger->shouldReceive('error')->times(1)->with('Could not complete "test" (uq)', ['exception' => $dispatchException]);
     $loggerSubscriber = new LoggerSubscriber('test', $logger, 'uq');
     $dispatcher = Mockery::mock(EventDispatcher::class);
     $dispatcher->makePartial();
     $dispatcher->shouldReceive('dispatch')->times(5)->passthru();
     $dispatcher->shouldReceive('addSubscriber')->times(1)->with($loggerSubscriber)->passthru();
     $executor = new Executor();
     $executor->setDispatcher($dispatcher);
     $executor->addSubscriber($loggerSubscriber);
     $executor->execute(1, $callable);
 }