Skip to content

Commit

Permalink
dev/core#2073 Improve cleanup on syntaxconformance test
Browse files Browse the repository at this point in the history
Cleaning up all objects seems a bit too much - but ensuring we
re-set the DAO we create in this class should be a memory-friendly action

#18639
  • Loading branch information
eileenmcnaughton committed Oct 1, 2020
1 parent 260e7da commit a8a2f26
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ public function setUp() {
'Payment',
'Order',
];
$this->onlyIDNonZeroCount['get'] = [
'ActivityType',
'Entity',
'Domain',
'Setting',
'User',
];
$this->deprecatedAPI = ['Location', 'ActivityType', 'SurveyRespondant'];
$this->deletableTestObjects = [];
}
Expand All @@ -128,6 +121,7 @@ public function tearDown() {
CRM_Core_DAO::deleteTestObjects($entityName, ['id' => $entityID]);
}
}
$this->deletableTestObjects = NULL;
}

/**
Expand Down Expand Up @@ -928,7 +922,7 @@ public function testAcceptsOnlyID_get($Entity) {
// just to get a clearer message in the log
$this->assertEquals("only id should be enough", $result['error_message']);
}
if (!in_array($Entity, $this->onlyIDNonZeroCount['get'])) {
if (!in_array($Entity, $this->getOnlyIDNonZeroCount(), TRUE)) {
$this->assertEquals(0, $result['count']);
}
}
Expand Down Expand Up @@ -987,7 +981,7 @@ public function testByID_get($entityName) {
}

$baos = $this->getMockableBAOObjects($entityName);
list($baoObj1, $baoObj2) = $baos;
[$baoObj1, $baoObj2] = $baos;

// fetch first by ID
$result = $this->callAPISuccess($entityName, 'get', [
Expand Down Expand Up @@ -1209,7 +1203,7 @@ public function testNonExistantID_get($Entity) {

$this->assertArrayHasKey('version', $result);
$this->assertEquals(3, $result['version']);
if (!in_array($Entity, $this->onlyIDNonZeroCount['get'])) {
if (!in_array($Entity, $this->getOnlyIDNonZeroCount(), TRUE)) {
$this->assertEquals(0, $result['count']);
}
}
Expand Down Expand Up @@ -1598,7 +1592,7 @@ public function testByID_delete($entityName) {
$startCount = $this->callAPISuccess($entityName, 'getcount', []);
$createcount = 2;
$baos = $this->getMockableBAOObjects($entityName, $createcount);
list($baoObj1, $baoObj2) = $baos;
[$baoObj1, $baoObj2] = $baos;

// make sure exactly 2 exist
$result = $this->callAPISuccess($entityName, 'getcount', [],
Expand Down Expand Up @@ -1837,4 +1831,19 @@ public function testEncodeWrite() {
]);
}

/**
* Get entities that have non-zero counts already.
*
* @return string[]
*/
protected function getOnlyIDNonZeroCount(): array {
return [
'ActivityType',
'Entity',
'Domain',
'Setting',
'User',
];
}

}

0 comments on commit a8a2f26

Please sign in to comment.