* This function exists to wrap api getValue function & check the result
* so we can ensure they succeed & throw exceptions without litterering the test with checks
* There is a type check in this
+ *
* @param string $entity
* @param array $params
- * @param null $count
- * @throws \Exception
+ * @param int $count
+ *
+ * @throws \CRM_Core_Exception
+ *
* @return array|int
*/
public function callAPISuccessGetCount($entity, $params, $count = NULL) {
];
$result = $this->civicrm_api($entity, 'getcount', $params);
if (!is_int($result) || !empty($result['is_error']) || isset($result['values'])) {
- throw new \Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
+ throw new \CRM_Core_Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
}
if (is_int($count)) {
$this->assertEquals($count, $result, "incorrect count returned from $entity getcount");
* - array
* - object
*
- * @throws \Exception
+ * @throws \CRM_Core_Exception
+ *
* @return array|int
*/
public function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) {
];
$result = $this->civicrm_api($entity, 'getsingle', $params);
if (!is_array($result) || !empty($result['is_error']) || isset($result['values'])) {
- $unfilteredResult = $this->civicrm_api($entity, 'get', $params);
- throw new \Exception(
+ $unfilteredResult = $this->civicrm_api($entity, 'get', ['version' => $this->_apiversion]);
+ throw new \CRM_Core_Exception(
'Invalid getsingle result' . print_r($result, TRUE)
. "\n entity: $entity . \n params \n " . print_r($params, TRUE)
. "\n entities retrieved with blank params \n" . print_r($unfilteredResult, TRUE)
*
* @return int
* id of Individual created
- * @throws \Exception
+ *
+ * @throws \CRM_Core_Exception
*/
public function individualCreate($params = array(), $seq = 0, $random = FALSE) {
$params = array_merge($this->sampleContact('Individual', $seq, $random), $params);
* @param array $params
* For civicrm_contact_add api function call.
*
- * @throws \Exception
+ * @throws CRM_Core_Exception
*
* @return int
* id of Household created
private function _contactCreate($params) {
$result = $this->callAPISuccess('contact', 'create', $params);
if (!empty($result['is_error']) || empty($result['id'])) {
- throw new \Exception('Could not create test contact, with message: ' . \CRM_Utils_Array::value('error_message', $result) . "\nBacktrace:" . \CRM_Utils_Array::value('trace', $result));
+ throw new \CRM_Core_Exception('Could not create test contact, with message: ' . \CRM_Utils_Array::value('error_message', $result) . "\nBacktrace:" . \CRM_Utils_Array::value('trace', $result));
}
return $result['id'];
}