Doctrine 在单元测试模拟中抛出\doctor\DBAL\Driver\DriverException
编辑单元测试时,我遇到了这个问题。我要测试的一段代码捕获了一个Doctrine 在单元测试模拟中抛出\doctor\DBAL\Driver\DriverException,doctrine,symfony-3.4,php-7.2,Doctrine,Symfony 3.4,Php 7.2,编辑单元测试时,我遇到了这个问题。我要测试的一段代码捕获了一个\doctor\DBAL\Exception\RetryableException。类链中的第一个构造函数是DriverException中的一个,构建方式如下: /** * @param string $message The exception message. * @param \Doctrine\DBAL\Driver\DriverExcepti
\doctor\DBAL\Exception\RetryableException
。类链中的第一个构造函数是DriverException
中的一个,构建方式如下:
/**
* @param string $message The exception message.
* @param \Doctrine\DBAL\Driver\DriverException $driverException The DBAL driver exception to chain.
*/
public function __construct($message, \Doctrine\DBAL\Driver\DriverException $driverException)
{
$exception = null;
if ($driverException instanceof Exception) {
$exception = $driverException;
}
parent::__construct($message, 0, $exception);
$this->driverException = $driverException;
}
我觉得我在这里面临着鸡蛋和鸡肉的问题。如何实例化一个首先将自身实例作为强制参数的类?注意:我不会将此自动响应标记为解决方案,它更像是一种变通方法 我没有在单元测试模拟中抛出正确的异常,而是创建了一个更简单的异常,扩展了
exception
,但仍然实现了原始接口RetryableException
,因为我正在测试的代码中捕获了该接口。虽然不是我想做的,但它确实符合我的要求