[REF][PHP8.2] Refactor getParticipantOrderParams to never write a dynamic property
authorBradley Taylor <hello@brad-taylor.co.uk>
Sat, 18 Mar 2023 17:30:14 +0000 (17:30 +0000)
committerBradley Taylor <hello@brad-taylor.co.uk>
Sat, 18 Mar 2023 17:30:14 +0000 (17:30 +0000)
tests/phpunit/CRM/Contact/Form/Search/Custom/PriceSetTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index e1cdec50e9d9c782c9f341cf2436e7aa20f56e57..d777f1451510c45e5095cae23de327a786c4df53 100644 (file)
 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
index 4e05b093cdec44a8a3c7ac45d2ecbe17ae621aea..5df560ec2236e4e88ad207a4874edcb0f49ebeb1 100644 (file)
@@ -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',