Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350117 )

Change subject: Update CiviFixtures to use civicrm_api3.
......................................................................

Update CiviFixtures to use civicrm_api3.

After trying latest Civi I have been hitting problems with Message: 
mysqli_free_result() [function.mysqli-free-result]: Couldn't fetch mysqli_result

After much distress I spotted a reference to suggest that cloning a DAO could 
cause it to be converted
to a serialized object rather than a true object. Replacing the class api calls 
with civicrm_api3 calls fixed this
locally for me.

The PEAR globals is to move a enotice handling routine from being a civi hack 
to within our test suite.
I don't expect it would affect live code (when we revert the hack from our civi 
code base)

Change-Id: I9530ad61020cde1b5a2e3bbe12d48c3ee968ff38
---
M sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php
M sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
2 files changed, 28 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/17/350117/1

diff --git a/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php 
b/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php
index e785a8e..b5eceae 100644
--- a/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php
+++ b/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php
@@ -21,29 +21,23 @@
      * @return CiviFixtures
      */
     static function create() {
+        civicrm_initialize();
         $out = new CiviFixtures();
 
-        $api = civicrm_api_classapi();
-
-        $contact_params = array(
-            'contact_type' => 'Individual',
-            'first_name' => 'Test',
-            'last_name' => 'Es',
-
-            'version' => 3,
-        );
-        $api->Contact->Create( $contact_params );
-        $out->contact_id = $api->id;
+        $individual = civicrm_api3('Contact', 'Create', array(
+          'contact_type' => 'Individual',
+          'first_name' => 'Test',
+          'last_name' => 'Es'
+        ));
+        $out->contact_id = $individual['id'];
 
         $out->org_contact_name = 'Test DAF ' . mt_rand();
-        $contact_params = array(
-            'contact_type' => 'Organization',
-            'organization_name' => $out->org_contact_name,
 
-            'version' => 3,
-        );
-        $api->Contact->Create( $contact_params );
-        $out->org_contact_id = $api->id;
+        $organization = civicrm_api3('Contact', 'Create', array(
+          'contact_type' => 'Organization',
+          'organization_name' => $out->org_contact_name,
+        ));
+        $out->org_contact_id = $organization['id'];
 
         $out->recur_amount = '2.34';
         $out->subscription_id = 'SUB-' . mt_rand();
@@ -67,43 +61,31 @@
 
             'version' => 3,
         );
-        $api->ContributionRecur->Create( $subscription_params );
-        $out->contribution_recur_id = $api->id;
+        $contributionRecur = civicrm_api3('ContributionRecur', 'Create', 
$subscription_params);
+        $out->contribution_recur_id = $contributionRecur['id'];
+
+        $group = civicrm_api3('OptionGroup', 'get', array('title' => 
$out->contact_group_name));
 
         // FIXME: Can't generate random groups because of caching in
         // CRM_Core_Pseudoconstant.  Make temp and random again once we're
         // using Civi 4.6's buildOptions.
         $out->contact_group_name = 'test_thrilled_demographic';
-        $success = $api->Group->Get( array(
-            'title' => $out->contact_group_name,
-            'version' => 3,
-        ) );
-        if ( $success && $api->count === 1 ) {
-            $out->contact_group_id = $api->id;
+
+        if ($group['count'] === 1 ) {
+            $out->contact_group_id = $group['id'];
         } else {
-            $success = $api->Group->Create( array(
-                'title' => $out->contact_group_name,
-                'version' => 3,
-            ) );
-            if ( !$success ) {
-                throw new Exception( $api->errorMsg() );
-            }
-            $out->contact_group_id = $api->id;
+            $group = civicrm_api3('OptionGroup', 'create', array('title' => 
$out->contact_group_name));
+            $out->contact_group_id = $group['id'];
         }
 
         return $out;
     }
 
-    // FIXME: probably need control over destruction order to not conflict 
with stuff added by test cases
+  /**
+   * Tear down function.
+   */
     public function __destruct() {
-        $api = civicrm_api_classapi();
-        $api->ContributionRecur->Delete( array(
-            'id' => $this->contribution_recur_id,
-            'version' => 3,
-        ) );
-        $api->Contact->Delete( array(
-            'id' => $this->contact_id,
-            'version' => 3,
-        ) );
+        civicrm_api3('ContributionRecur', 'delete', array('id' => 
$this->contribution_recur_id));
+        civicrm_api3('Contact', 'delete', array('id' => $this->contact_id));
     }
 }
diff --git 
a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php 
b/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
index 2d61a49..7f8ccaa 100644
--- 
a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
+++ 
b/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
@@ -11,6 +11,8 @@
         }
 
         global $user, $_exchange_rate_cache;
+        $GLOBALS['_PEAR_default_error_mode'] = NULL;
+        $GLOBALS['_PEAR_default_error_options'] = NULL;
         $_exchange_rate_cache = array();
 
         $user = new stdClass();

-- 
To view, visit https://gerrit.wikimedia.org/r/350117
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9530ad61020cde1b5a2e3bbe12d48c3ee968ff38
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to