From 37eb13b25d5f83d0bef7580c5892d348408e20b2 Mon Sep 17 00:00:00 2001 From: Mattias Michaux Date: Thu, 19 May 2016 16:50:59 +0200 Subject: [PATCH] Drasticly reduce memory usage during tests. --- CRM/Core/DAO.php | 9 +++++---- tests/phpunit/api/v3/SyntaxConformanceTest.php | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index cb02a95c57..a168da8b3e 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -147,26 +147,26 @@ class CRM_Core_DAO extends DB_DataObject { if ($fkDAO->find(TRUE)) { $this->$dbName = $fkDAO->id; } - unset($fkDAO); + $fkDAO->free(); } elseif (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) { $depObject = new $FKClassName(); $depObject->find(TRUE); $this->$dbName = $depObject->id; - unset($depObject); + $depObject->free(); } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $fieldName == 'member_of_contact_id') { // FIXME: the fields() metadata is not specific enough $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization')); $this->$dbName = $depObject->id; - unset($depObject); + $depObject->free(); } else { //if it is required we need to generate the dependency object first $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1)); $this->$dbName = $depObject->id; - unset($depObject); + $depObject->free(); } } @@ -520,6 +520,7 @@ class CRM_Core_DAO extends DB_DataObject { $event = new \Civi\Core\DAO\Event\PostDelete($this, $result); \Civi::service('dispatcher')->dispatch("DAO::post-delete", $event); + $this->free(); return $result; } diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 9463b5a17e..e1af7dcfa7 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -899,6 +899,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { for ($i = 0; $i < 30; $i++) { $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); $ids[] = $baoObj->id; + $baoObj->free(); } // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount) @@ -945,6 +946,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { for ($i = 0; $i < 3 - $totalEntities; $i++) { $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD')); $ids[] = $baoObj->id; + $baoObj->free(); } $totalEntities = 3; } -- 2.25.1