/**
  * Test whether exceptions are handled by the exception handler passed to the try catch wrapper
  */
 public function testHandleExceptions()
 {
     $expectedException = new Exception();
     $client = $this->getMockForAbstractClass(Redis::class, array('set'));
     $client->expects($this->once())->method('set')->will($this->throwException($expectedException));
     $connection = $this->getMockForAbstractClass(Connection::class, array('getClient'));
     $connection->expects($this->any())->method('getClient')->will($this->returnValue($client));
     $handler = $this->getMockBuilder(ExceptionHandler::class)->setMethods(array('handleException'))->getMock();
     $handler->expects($this->once())->method('handleException')->with($expectedException)->will($this->returnValue(ExceptionStrategy::DISCARD()));
     $wrapper = new TryCatchWrapper($connection, $handler);
     $wrapper->set('testKey', 'testValue');
 }
Example #2
0
 /**
  * @param Connection $conn
  * @param array $config
  * @return TryCatchWrapper
  */
 private function wrapInTryCatch(Connection $conn, array $config)
 {
     $wrapper = new TryCatchWrapper($conn, $this->logger);
     if (isset($config['defaultHandlerStrategy'])) {
         $strategy = ExceptionStrategy::fromValue((string) $config['defaultHandlerStrategy']);
         $wrapper->setDefaultHandlerStrategy($strategy);
     }
     return $wrapper;
 }