Commit 87476831 authored by Rich's avatar Rich Committed by mattwire
Browse files

Add handleErrorThrowsException option (to help with testing)

parent e27c7746
...@@ -36,6 +36,11 @@ trait CRM_Core_Payment_MJWTrait { ...@@ -36,6 +36,11 @@ trait CRM_Core_Payment_MJWTrait {
*/ */
private $paymentProcessorSubscriptionID; private $paymentProcessorSubscriptionID;
/**
* @var bool Throw an exception in handleError.
*/
public $handleErrorThrowsException = FALSE;
/** /**
* Get the billing email address * Get the billing email address
* *
...@@ -354,6 +359,10 @@ trait CRM_Core_Payment_MJWTrait { ...@@ -354,6 +359,10 @@ trait CRM_Core_Payment_MJWTrait {
$message = $errorCode . $errorMessage; $message = $errorCode . $errorMessage;
Civi::log()->error($this->getPaymentTypeLabel() . ' Payment Error: ' . $message); Civi::log()->error($this->getPaymentTypeLabel() . ' Payment Error: ' . $message);
if ($this->handleErrorThrowsException) {
// We're in a test environment. Throw exception.
throw new \Exception('Exception thrown to avoid statusBounce because handleErrorThrowsException is set.' . $message);
}
if ($bounceURL) { if ($bounceURL) {
CRM_Core_Error::statusBounce($message, $bounceURL, $this->getPaymentTypeLabel()); CRM_Core_Error::statusBounce($message, $bounceURL, $this->getPaymentTypeLabel());
...@@ -370,6 +379,13 @@ trait CRM_Core_Payment_MJWTrait { ...@@ -370,6 +379,13 @@ trait CRM_Core_Payment_MJWTrait {
return $this->_paymentProcessor['name']; return $this->_paymentProcessor['name'];
} }
/**
* Allow (phpunit test code) to configure handleError to throw an exception,
* thereby avoiding a statusBounce which is hard to deal with in tests.
*/
public function setHandleErrorThrowsException(bool $value) {
$this->handleErrorThrowsException = $value;
}
/** /**
* Set the payment processor Transaction ID * Set the payment processor Transaction ID
* *
......
...@@ -17,6 +17,7 @@ Releases use the following numbering system: ...@@ -17,6 +17,7 @@ Releases use the following numbering system:
* IPN data can be array, object or string. * IPN data can be array, object or string.
* Clear cancel_date when setting a contribution back to pending. * Clear cancel_date when setting a contribution back to pending.
* Support CiviCRM multi-domain (add default domain to API calls). * Support CiviCRM multi-domain (add default domain to API calls).
* Add `handleErrorThrowsException` option to MJWTrait (to help with testing).
## Release 0.9.12 ## Release 0.9.12
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment