test/phpunit/api/v3 - Fix spooky interaction
authorTim Otten <totten@civicrm.org>
Fri, 17 Mar 2023 03:51:34 +0000 (20:51 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 17 Mar 2023 04:02:11 +0000 (21:02 -0700)
This fixes an issue observed in review of 25673. With that patch included,
`JobProcessMailingTest` would still pass... but only in isolation. When
combined with `ExceptionTest`, it would fail.

I tried disabling the entire substance of `ExceptionTest`, and it still
failed. Say what?

The problem was _the order_ in which `ExceptionTest` does its initialization
(`parent::setUp()` and `$this->useTransaction()`). I suppose that order
determines the effectiveness of the transaction.

Most tests call `setup()` then `useTransaction()`. I looked for
outliers which flipped the order -- and found `EntityTagACLTest`
has the same init and the same spooky interaction.

After fixing the outliers, I'm getting the expected results on
`JobProcessMailingTest`.

tests/phpunit/api/v3/EntityTagACLTest.php
tests/phpunit/api/v3/ExceptionTest.php
tests/phpunit/api/v3/PaymentTokenTest.php
tests/phpunit/api/v3/SurveyTest.php

index b7c06fa651216bb3f5b17f999c14d518e09cafc3..66623d2f5344e8783cfb8e0f8b779252d390e9bc 100644 (file)
@@ -46,8 +46,8 @@ class api_v3_EntityTagACLTest extends CiviUnitTestCase {
    * Set up permissions for test.
    */
   public function setUp(): void {
-    $this->useTransaction(TRUE);
     parent::setUp();
+    $this->useTransaction(TRUE);
     $individualID = $this->individualCreate();
     $daoObj = new CRM_Core_DAO();
     $this->callAPISuccess('Attachment', 'create', [
index 1a5e38baf08677135139f7c3a6d5c97925ed2ec8..cd52cc2ab6a8dd400190f3ae158f5eb46dd3e376 100644 (file)
@@ -23,8 +23,8 @@ class api_v3_ExceptionTest extends CiviUnitTestCase {
    * This method is called before a test is executed.
    */
   protected function setUp(): void {
-    $this->useTransaction(TRUE);
     parent::setUp();
+    $this->useTransaction(TRUE);
   }
 
   /**
index 51f5401cd03ebd54e4643831ec82ee14c40d20de..d5219f4ff36f1f17596e78632c41b8b70e0a7c77 100644 (file)
@@ -23,8 +23,8 @@ class api_v3_PaymentTokenTest extends CiviUnitTestCase {
    * @throws \CRM_Core_Exception
    */
   public function setUp(): void {
-    $this->useTransaction();
     parent::setUp();
+    $this->useTransaction();
     $contactID = $this->individualCreate();
     $this->params = [
       'token' => "fancy-token-xxxx",
index 6713719e4736092e5afb420a18b087064c116dff..e9bedd70612a0401ba16cb4e673937d4381027e6 100644 (file)
@@ -33,6 +33,7 @@ class api_v3_SurveyTest extends CiviUnitTestCase {
   protected $entity = 'survey';
 
   public function setUp(): void {
+    parent::setUp();
     $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', [
       'label' => 'PhoneBank',
       'return' => 'value',
@@ -45,7 +46,6 @@ class api_v3_SurveyTest extends CiviUnitTestCase {
       'max_number_of_contacts' => 12,
       'instructions' => "Call people, ask for money",
     ];
-    parent::setUp();
   }
 
   /**