Skip to content

Commit

Permalink
Merge pull request #20038 from mattwire/suppresswarnings
Browse files Browse the repository at this point in the history
Suppress legacy warnings by default in propertyBag to allow transition to propertyBag without hitting legacy warnings on unconverted payment processors
  • Loading branch information
seamuslee001 authored Apr 12, 2021
2 parents de02266 + 5456ba9 commit 437d4cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Civi/Payment/PropertyBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,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.
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Civi/Payment/PropertyBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function testSetContactIDFailsIfInvalid() {
*/
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.
Expand Down Expand Up @@ -191,6 +192,7 @@ public function testSetCustomProp() {

// 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 {
Expand Down

0 comments on commit 437d4cb

Please sign in to comment.