From: Matthew Wire Date: Sun, 11 Apr 2021 21:56:34 +0000 (+0100) Subject: Suppress legacy warnings by default in propertyBag to allow transition to propertyBag... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5456ba915e9514f6719bc1617611a647ab4170e3;p=civicrm-core.git Suppress legacy warnings by default in propertyBag to allow transition to propertyBag without hitting legacy warnings on unconverted payment processors --- diff --git a/Civi/Payment/PropertyBag.php b/Civi/Payment/PropertyBag.php index daf716c7c0..1af17c123a 100644 --- a/Civi/Payment/PropertyBag.php +++ b/Civi/Payment/PropertyBag.php @@ -77,8 +77,29 @@ class PropertyBag implements \ArrayAccess { * @var bool * Temporary, internal variable to help ease transition to PropertyBag. * Used by cast() to suppress legacy warnings. + * For paymentprocessors that have not converted to propertyBag we need to support "legacy" properties - eg. "is_recur" + * without warnings. Setting this allows us to pass a propertyBag into doPayment() and expect it to "work" with + * existing payment processors. */ - protected $suppressLegacyWarnings = FALSE; + protected $suppressLegacyWarnings = TRUE; + + /** + * Get the value of the suppressLegacyWarnings parameter + * @return bool + */ + public function getSuppressLegacyWarnings() { + return $this->suppressLegacyWarnings; + } + + /** + * Set the suppressLegacyWarnings parameter - useful for unit tests. + * Eg. you could set to FALSE for unit tests on a paymentprocessor to capture use of legacy keys in that processor + * code. + * @param bool $suppressLegacyWarnings + */ + public function setSuppressLegacyWarnings(bool $suppressLegacyWarnings) { + $this->suppressLegacyWarnings = $suppressLegacyWarnings; + } /** * Get the property bag. diff --git a/tests/phpunit/Civi/Payment/PropertyBagTest.php b/tests/phpunit/Civi/Payment/PropertyBagTest.php index b127f10ee4..892fec2254 100644 --- a/tests/phpunit/Civi/Payment/PropertyBagTest.php +++ b/tests/phpunit/Civi/Payment/PropertyBagTest.php @@ -109,6 +109,7 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt */ public function testSetContactIDLegacyWay() { $propertyBag = new PropertyBag(); + $propertyBag->setSuppressLegacyWarnings(FALSE); // To prevent E_USER_DEPRECATED errors during phpunit tests we take a copy // of the existing error_reporting. @@ -191,6 +192,7 @@ class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInt // Test we can do this with array, although we should get a warning. $propertyBag = new PropertyBag(); + $propertyBag->setSuppressLegacyWarnings(FALSE); // Set by array access should cause deprecated error. try {