public function testConvertsException()
 {
     if (!$this->driver instanceof ExceptionConverterDriver) {
         $this->markTestSkipped('This test is only intended for exception converter drivers.');
     }
     $data = $this->getExceptionConversions();
     if (empty($data)) {
         $this->fail(sprintf('No test data found for test %s. You have to return test data from %s.', get_class($this) . '::' . __FUNCTION__, get_class($this) . '::getExceptionConversionData'));
     }
     $driverException = $this->getMock('Doctrine\\DBAL\\Driver\\DriverException');
     $driverException->expects($this->any())->method('getErrorCode')->will($this->returnValue('foo'));
     $driverException->expects($this->any())->method('getSQLState')->will($this->returnValue('bar'));
     $driverException->expects($this->any())->method('getMessage')->will($this->returnValue('baz'));
     $data[] = array($driverException, self::EXCEPTION_DRIVER);
     $message = 'DBAL exception message';
     foreach ($data as $item) {
         /** @var $driverException \Doctrine\DBAL\Driver\DriverException */
         list($driverException, $convertedExceptionClassName) = $item;
         $convertedException = $this->driver->convertException($message, $driverException);
         $this->assertSame($convertedExceptionClassName, get_class($convertedException));
         $this->assertSame($driverException->getErrorCode(), $convertedException->getErrorCode());
         $this->assertSame($driverException->getSQLState(), $convertedException->getSQLState());
         $this->assertSame($message, $convertedException->getMessage());
     }
 }
Example #2
0
 /**
  * @param \Doctrine\DBAL\Driver     $driver
  * @param \Exception $driverEx
  *
  * @return \Doctrine\DBAL\DBALException
  */
 public static function driverException(Driver $driver, \Exception $driverEx)
 {
     $msg = "An exception occurred in driver: " . $driverEx->getMessage();
     if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverException) {
         return $driver->convertException($msg, $driverEx);
     }
     return new self($msg, 0, $driverEx);
 }
Example #3
0
 /**
  * @param \Doctrine\DBAL\Driver     $driver
  * @param \Exception $driverEx
  *
  * @return \Doctrine\DBAL\DBALException
  */
 private static function wrapException(Driver $driver, \Exception $driverEx, $msg)
 {
     if ($driverEx instanceof Exception\DriverException) {
         return $driverEx;
     }
     if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof Driver\DriverException) {
         return $driver->convertException($msg, $driverEx);
     }
     return new self($msg, 0, $driverEx);
 }