From 6e03796d2266a4d0ecb43c7bdf83c971f07e4762 Mon Sep 17 00:00:00 2001 From: Bradley Taylor Date: Sat, 18 Mar 2023 17:30:14 +0000 Subject: [PATCH] [REF][PHP8.2] Refactor getParticipantOrderParams to never write a dynamic property --- .../Contact/Form/Search/Custom/PriceSetTest.php | 5 +++-- tests/phpunit/CiviTest/CiviUnitTestCase.php | 17 +++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/PriceSetTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/PriceSetTest.php index e1cdec50e9..d777f14515 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/PriceSetTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/PriceSetTest.php @@ -57,13 +57,14 @@ class CRM_Contact_Form_Search_Custom_PriceSetTest extends CiviUnitTestCase { public function testRunSearch() { - $order = $this->callAPISuccess('Order', 'create', $this->getParticipantOrderParams()); + $event = $this->eventCreate(); + $order = $this->callAPISuccess('Order', 'create', $this->getParticipantOrderParams($event['id'])); $this->callAPISuccess('Payment', 'create', [ 'order_id' => $order['id'], 'total_amount' => 50, ]); $this->validateAllPayments(); - $formValues = ['event_id' => $this->_eventId]; + $formValues = ['event_id' => $event['id']]; $form = new CRM_Contact_Form_Search_Custom_PriceSet($formValues); $sql = $form->all(); // Assert that we have created a standard temp table diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 4e05b093cd..5df560ec22 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3432,19 +3432,24 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { /** * Get parameters to set up a multi-line participant order. * + * @param null|int $eventId + * Optional event ID. A new event will be created if no event ID is given. * @return array * @throws \CRM_Core_Exception */ - protected function getParticipantOrderParams(): array { - $event = $this->eventCreate(); - $this->_eventId = $event['id']; + protected function getParticipantOrderParams($eventId = NULL): array { + if (!$eventId) { + $event = $this->eventCreate(); + $eventId = $event['id']; + } + $eventParams = [ - 'id' => $this->_eventId, + 'id' => $eventId, 'financial_type_id' => 4, 'is_monetary' => 1, ]; $this->callAPISuccess('event', 'create', $eventParams); - $priceFields = $this->createPriceSet('event', $this->_eventId); + $priceFields = $this->createPriceSet('event', $eventId); $orderParams = [ 'total_amount' => 300, 'currency' => 'USD', @@ -3469,7 +3474,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { ], 'params' => [ 'financial_type_id' => 4, - 'event_id' => $this->_eventId, + 'event_id' => $eventId, 'role_id' => 1, 'status_id' => 14, 'fee_currency' => 'USD', -- 2.25.1