Merge pull request #5058 from eileenmcnaughton/test-examples
[civicrm-core.git] / api / v3 / examples / Contact / GetCountContact.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using contact getcount API.
10 *
11 * This demonstrates use of the 'getCount' action.
12 *
13 * This param causes the count of the only function to be returned as an integer.
14 *
15 * @return array
16 * API result array
17 */
18 function contact_getcount_example() {
19 $params = array(
20 'id' => 17,
21 );
22
23 try{
24 $result = civicrm_api3('contact', 'getcount', $params);
25 }
26 catch (CiviCRM_API3_Exception $e) {
27 // Handle error here.
28 $errorMessage = $e->getMessage();
29 $errorCode = $e->getErrorCode();
30 $errorData = $e->getExtraParams();
31 return array(
32 'error' => $errorMessage,
33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 );
36 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function contact_getcount_expectedresult() {
48
49 $expectedResult = 1;
50
51 return $expectedResult;
52 }
53
54 /**
55 * This example has been generated from the API test suite.
56 * The test that created it is called
57 * testContactGetFormatCount_only
58 * and can be found in
59 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
60 *
61 * You can see the outcome of the API tests at
62 * https://test.civicrm.org/job/CiviCRM-master-git/
63 *
64 * To Learn about the API read
65 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
66 *
67 * Browse the api on your own site with the api explorer
68 * http://MYSITE.ORG/path/to/civicrm/api/explorer
69 *
70 * Read more about testing here
71 * http://wiki.civicrm.org/confluence/display/CRM/Testing
72 *
73 * API Standards documentation:
74 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
75 */