Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $params type declaration to global API functions. #15852

Merged
merged 2 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @return array|int
*/
function civicrm_api($entity, $action, $params, $extra = NULL) {
function civicrm_api($entity, $action, array $params, $extra = NULL) {
return \Civi::service('civi_api_kernel')->runSafe($entity, $action, $params, $extra);
}

Expand All @@ -37,7 +37,7 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
* @throws \API_Exception
* @throws \Civi\API\Exception\NotImplementedException
*/
function civicrm_api4($entity, $action, $params = [], $index = NULL) {
function civicrm_api4($entity, $action, array $params = [], $index = NULL) {
$apiCall = \Civi\Api4\Utils\ActionUtil::getAction($entity, $action);
foreach ($params as $name => $param) {
$setter = 'set' . ucfirst($name);
Expand Down Expand Up @@ -81,7 +81,7 @@ function civicrm_api4($entity, $action, $params = [], $index = NULL) {
*
* @return array
*/
function civicrm_api3($entity, $action, $params = []) {
function civicrm_api3($entity, $action, array $params = []) {
$params['version'] = 3;
$result = \Civi::service('civi_api_kernel')->runSafe($entity, $action, $params);
if (is_array($result) && !empty($result['is_error'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1752,9 +1752,9 @@ public function testDeleteEmptyParamsContribution() {
}

public function testDeleteParamsNotArrayContribution() {
$this->expectException(TypeError::class);
$params = 'contribution_id= 1';
$contribution = $this->callAPIFailure('contribution', 'delete', $params);
$this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array');
}

public function testDeleteWrongParamContribution() {
Expand Down
19 changes: 0 additions & 19 deletions tests/phpunit/api/v3/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ public function tearDown() {
parent::tearDown();
}

/**
* Check with no array.
*/
public function testCustomFieldCreateNoArray() {
$fieldParams = NULL;

$customField = $this->callAPIFailure('custom_field', 'create', $fieldParams);
$this->assertEquals($customField['error_message'], 'Input variable `params` is not an array');
}

/**
* Check with no label.
*/
Expand Down Expand Up @@ -406,15 +396,6 @@ public function testCustomFieldCreateWithOptionValues() {

///////////////// civicrm_custom_field_delete methods

/**
* Check with no array.
*/
public function testCustomFieldDeleteNoArray() {
$params = NULL;
$customField = $this->callAPIFailure('custom_field', 'delete', $params);
$this->assertEquals($customField['error_message'], 'Input variable `params` is not an array');
}

/**
* Check without Field ID.
*/
Expand Down
18 changes: 0 additions & 18 deletions tests/phpunit/api/v3/CustomGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,6 @@ public function testCustomGroupCreateNoStyle() {
$this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline');
}

/**
* Check with not array.
*/
public function testCustomGroupCreateNotArray() {
$params = NULL;
$customGroup = $this->callAPIFailure('custom_group', 'create', $params);
$this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array');
}

/**
* Check without title.
*/
Expand Down Expand Up @@ -336,15 +327,6 @@ public function testCustomGroupDeleteWithoutGroupID() {
$this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id');
}

/**
* Check with no array.
*/
public function testCustomGroupDeleteNoArray() {
$params = NULL;
$customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
$this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array');
}

/**
* Check with valid custom group id.
*/
Expand Down
11 changes: 0 additions & 11 deletions tests/phpunit/api/v3/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,6 @@ public function testDeleteWithWrongEventId($version) {
$result = $this->callAPIFailure('Event', 'Delete', $params);
}

/**
* Test civicrm_event_search with wrong params type.
* @param int $version
* @dataProvider versionThreeAndFour
*/
public function testSearchWrongParamsType($version) {
$this->_apiversion = $version;
$params = 'a string';
$result = $this->callAPIFailure('event', 'get', $params);
}

/**
* Test civicrm_event_search with empty params.
* @param int $version
Expand Down
33 changes: 0 additions & 33 deletions tests/phpunit/api/v3/GroupOrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,6 @@ public function testGroupOrganizationGetWithEmptyParams() {
$this->assertAPISuccess($result);
}

/**
* Test civicrm_group_organization_get with wrong params.
*
* @dataProvider versionThreeAndFour
*/
public function testGroupOrganizationGetWithWrongParams() {
$params = 'groupOrg';
$result = $this->callAPIFailure('group_organization', 'get', $params);
$this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
}

/**
* Test civicrm_group_organization_get invalid keys.
*
Expand Down Expand Up @@ -149,17 +138,6 @@ public function testGroupOrganizationCreateWithEmptyParams() {
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
}

/**
* Check with invalid params.
*
* @dataProvider versionThreeAndFour
*/
public function testGroupOrganizationCreateParamsNotArray() {
$params = 'group_org';
$result = $this->callAPIFailure('group_organization', 'create', $params);
$this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
}

/**
* Check with invalid params keys.
*
Expand All @@ -175,17 +153,6 @@ public function testGroupOrganizationCreateWithInvalidKeys() {

///////////////// civicrm_group_organization_remove methods

/**
* Test civicrm_group_organization_remove with params not an array.
*
* @dataProvider versionThreeAndFour
*/
public function testGroupOrganizationDeleteParamsNotArray() {
$params = 'delete';
$result = $this->callAPIFailure('group_organization', 'delete', $params);
$this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
}

/**
* Test civicrm_group_organization_remove with empty params.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/api/v3/JobProcessMailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public function testMailNonProductionRun() {
]);
$this->callAPISuccess('mailing', 'create', $this->_params);
$this->_mut->assertRecipients([]);
$this->callAPIFailure('job', 'process_mailing', "Failure in api call for job process_mailing: Job has not been executed as it is a non-production environment.");
$result = $this->callAPIFailure('job', 'process_mailing', []);
$this->assertEquals($result['error_message'], "Job has not been executed as it is a Staging (non-production) environment.");

// Test with runInNonProductionEnvironment param.
$this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]);
Expand Down
14 changes: 0 additions & 14 deletions tests/phpunit/api/v3/MailingContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,6 @@ public function tearDown() {
parent::tearDown();
}

/**
* Test that the api responds correctly to null params.
*
* Do not copy and paste.
*
* Tests like this that test the wrapper belong in the SyntaxConformance class
* (which already has a 'not array test)
* I have left this here in case 'null' isn't covered in that class
* but don't copy it only any other classes
*/
public function testMailingNullParams() {
$this->callAPIFailure('MailingContact', 'get', NULL);
}

public function testMailingContactGetFields() {
$result = $this->callAPISuccess('MailingContact', 'getfields', [
'action' => 'get',
Expand Down
8 changes: 0 additions & 8 deletions tests/phpunit/api/v3/MembershipPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ public function testCreate() {

///////////////// civicrm_membershipPayment_get methods

/**
* Test civicrm_membershipPayment_get with wrong params type.
*/
public function testGetWrongParamsType() {
$params = 'eeee';
$GetWrongParamsType = $this->callAPIFailure('membership_payment', 'get', $params, 'Input variable `params` is not an array');
}

/**
* Test civicrm_membershipPayment_get - success expected.
*/
Expand Down
8 changes: 0 additions & 8 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ public function testMembershipDeleteInvalidID() {
$this->callAPIFailure('membership', 'delete', ['id' => 'blah']);
}

/**
* Test civicrm_membership_delete() with invalid Membership Id.
*/
public function testMembershipDeleteWithInvalidMembershipId() {
$membershipId = 'membership';
$this->callAPIFailure('membership', 'delete', $membershipId);
}

/**
* Test membership deletion and with the preserve contribution param.
*/
Expand Down
25 changes: 0 additions & 25 deletions tests/phpunit/api/v3/ParticipantPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ public function setUp() {
]);
}

/**
* Test civicrm_participant_payment_create with wrong params type.
*/
public function testPaymentCreateWrongParamsType() {
$params = 'a string';
$this->callAPIFailure('participant_payment', 'create', $params);
}

/**
* Test civicrm_participant_payment_create with empty params.
*/
Expand Down Expand Up @@ -130,15 +122,6 @@ public function testPaymentInfoForEvent() {

///////////////// civicrm_participant_payment_create methods

/**
* Test civicrm_participant payment create with wrong params type.
*/
public function testPaymentUpdateWrongParamsType() {
$params = 'a string';
$result = $this->callAPIFailure('participant_payment', 'create', $params);
$this->assertEquals('Input variable `params` is not an array', $result['error_message']);
}

/**
* Check with empty array.
*/
Expand Down Expand Up @@ -268,14 +251,6 @@ public function testPaymentPayLaterOnline() {
$this->callAPISuccess('participant_payment', 'delete', $params);
}

/**
* Test civicrm_participant_payment_delete with wrong params type.
*/
public function testPaymentDeleteWrongParamsType() {
$params = 'a string';
$this->callAPIFailure('participant_payment', 'delete', $params);
}

/**
* Check with empty array.
*/
Expand Down
17 changes: 0 additions & 17 deletions tests/phpunit/api/v3/ParticipantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,6 @@ public function testUpdateCreateParticipantFeeLevelNoSeparator() {

///////////////// civicrm_participant_update methods

/**
* Test civicrm_participant_update with wrong params type.
*/
public function testUpdateWrongParamsType() {
$params = 'a string';
$result = $this->callAPIFailure('participant', 'create', $params);
$this->assertEquals('Input variable `params` is not an array', $result['error_message']);
}

/**
* Check with empty array.
*/
Expand Down Expand Up @@ -720,14 +711,6 @@ public function testUpdateWithWrongContactId() {

///////////////// civicrm_participant_delete methods

/**
* Test civicrm_participant_delete with wrong params type.
*/
public function testDeleteWrongParamsType() {
$params = 'a string';
$result = $this->callAPIFailure('participant', 'delete', $params);
}

/**
* Test civicrm_participant_delete with empty params.
*/
Expand Down
15 changes: 0 additions & 15 deletions tests/phpunit/api/v3/PaymentProcessorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ public function testPaymentProcessorTypeDeleteEmpty() {
$result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
}

/**
* Check with No array.
*/
public function testPaymentProcessorTypeDeleteParamsNotArray() {
$result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
}

/**
* Check if required fields are not passed.
*/
Expand Down Expand Up @@ -141,14 +134,6 @@ public function testPaymentProcessorTypeUpdateEmpty() {
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
}

/**
* Check with No array.
*/
public function testPaymentProcessorTypeUpdateParamsNotArray() {
$result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
$this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
}

/**
* Check with all parameters.
*/
Expand Down
11 changes: 0 additions & 11 deletions tests/phpunit/api/v3/RelationshipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,6 @@ public function testRelationshipTypesGetEmptyParams($version) {
$this->assertEquals(2, $results['count']);
}

/**
* Check with params Not Array.
* @param int $version
* @dataProvider versionThreeAndFour
*/
public function testRelationshipTypesGetParamsNotArray($version) {
$this->_apiversion = $version;

$results = $this->callAPIFailure('relationship_type', 'get', 'string');
}

/**
* Check with valid params array.
* @param int $version
Expand Down
Loading