private $_membershipStatusID;
private $_membershipTypeID;
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Exception
+ */
public function setUp(): void {
parent::setUp();
$this->_contactID = $this->organizationCreate();
$this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);
// add a random number to avoid silly conflicts with old data
- $this->_membershipStatusID = $this->membershipStatusCreate('test status' . rand(1, 1000));
+ $this->_membershipStatusID = $this->membershipStatusCreate('test status' . random_int(1, 1000));
}
/**
'duration_unit' => "year",
'duration_interval' => 1,
'period_type' => "rolling",
- 'name' => 'Organiation Membership Type',
+ 'name' => 'Organization Membership Type',
'relationship_type_id' => ($withRelationship) ? 5 : NULL,
'relationship_direction' => ($withRelationship) ? 'b_a' : NULL,
'max_related' => $maxRelated ?: NULL,
/**
* Get count of related memberships by parent membership id.
+ *
* @param $membershipId
+ *
* @return array|int
+ * @throws \CRM_Core_Exception
*/
private function getRelatedMembershipsCount($membershipId) {
return $this->callAPISuccess("Membership", "getcount", [
}
/**
- * Test to delete related membership when type of parent memebrship is changed which does not have relation type associated.
- * @throws CRM_Core_Exception
+ * Test to delete related membership when type of parent membership is changed which does not have relation type associated.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testDeleteRelatedMembershipsOnParentTypeChanged() {
+ public function testDeleteRelatedMembershipsOnParentTypeChanged(): void {
$contactId = $this->individualCreate();
$membershipOrganizationId = $this->organizationCreate();
// Update membership by changing it's type. New membership type is without relationship.
$membership["membership_type_id"] = $membershipTypeWithoutRelationship["id"];
- $updatedMembership = $this->callAPISuccess("Membership", "create", $membership);
+ $this->callAPISuccess("Membership", "create", $membership);
// Check count of related memberships again. It should be zero as we changed the membership type.
$relatedMembershipsCount = $this->getRelatedMembershipsCount($membership["id"]);
$this->membershipDelete($membership["id"]);
}
- public function testCreate() {
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testCreate(): void {
- list($contactId, $membershipId) = $this->setupMembership();
+ [$contactId, $membershipId] = $this->setupMembership();
// Now call create() to modify an existing Membership
$params = [
$this->contactDelete($contactId);
}
- public function testGetValues() {
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testGetValues(): void {
// $this->markTestSkipped( 'causes mysterious exit, needs fixing!' );
// Calculate membership dates based on the current date
$now = time();
$this->contactDelete($contactId);
}
- public function testRetrieve() {
- list($contactId, $membershipId) = $this->setupMembership();
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testRetrieve(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
$params = ['id' => $membershipId];
$values = [];
CRM_Member_BAO_Membership::retrieve($params, $values);
$this->contactDelete($contactId);
}
- public function testActiveMembers() {
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testActiveMembers(): void {
$contactId = $this->individualCreate();
$params = [
$this->assertEquals($activeMembers[$membershipId1]['id'], $membership[$membershipId1]['id'], 'Verify active membership record is retrieved.');
$this->assertEquals($activeMembers[$membershipId2]['id'], $membership[$membershipId2]['id'], 'Verify active membership record is retrieved.');
- $this->assertEquals(0, count($inActiveMembers), 'Verify No inactive membership record is retrieved.');
+ $this->assertCount(0, $inActiveMembers, 'Verify No inactive membership record is retrieved.');
$this->membershipDelete($membershipId1);
$this->membershipDelete($membershipId2);
$this->contactDelete($contactId);
}
- public function testDeleteMembership() {
- list($contactId, $membershipId) = $this->setupMembership();
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testDeleteMembership(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
CRM_Member_BAO_Membership::del($membershipId);
$this->assertDBNull('CRM_Member_BAO_Membership', $contactId, 'id',
$this->contactDelete($contactId);
}
- public function testGetContactMembership() {
- list($contactId, $membershipId) = $this->setupMembership();
-
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testGetContactMembership(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
$membership = CRM_Member_BAO_Membership::getContactMembership($contactId, $this->_membershipTypeID, FALSE);
$this->assertEquals($membership['id'], $membershipId, 'Verify membership record is retrieved.');
/**
* Get the contribution.
* page id from the membership record
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testgetContributionPageId() {
- list($contactId, $membershipId) = $this->setupMembership();
+ public function testGetContributionPageId(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
$membership[$membershipId]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($membershipId);
$this->membershipDelete($membershipId);
* Get membership joins/renewals
* for a specified membership
* type.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testgetMembershipStarts() {
- list($contactId, $membershipId) = $this->setupMembership();
+ public function testGetMembershipStarts(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
$yearStart = date('Y') . '0101';
$currentDate = date('Ymd');
CRM_Member_BAO_Membership::getMembershipStarts($this->_membershipTypeID, $yearStart, $currentDate);
/**
* Get a count of membership for a specified membership type,
* optionally for a specified date.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testGetMembershipCount() {
- list($contactId, $membershipId) = $this->setupMembership();
+ public function testGetMembershipCount(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
$currentDate = date('Ymd');
$test = 0;
CRM_Member_BAO_Membership::getMembershipCount($this->_membershipTypeID, $currentDate, $test);
/**
* Checkup sort name function.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testSortName() {
+ public function testSortName(): void {
$contactId = $this->individualCreate();
$params = [
/**
* Delete related memberships.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testdeleteRelatedMemberships() {
- list($contactId, $membershipId) = $this->setupMembership();
+ public function testDeleteRelatedMemberships(): void {
+ [$contactId, $membershipId] = $this->setupMembership();
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId);
/**
* Renew membership with change in membership type.
*
- * @fixme Note that this test fails when today is August 29 2019 (and maybe other years?):
- * Verify correct end date is calculated after membership renewal
- * Failed asserting that two strings are equal.
- * Expected-'2021-03-01'
- * Actual+'2021-02-28'
- * /home/jenkins/bknix-dfl/build/core-15165-73etc/web/sites/all/modules/civicrm/tests/phpunit/CRM/Member/BAO/MembershipTest.php:609
+ * @fixme Note that this test fails when today is August 29 2019 (and maybe
+ * other years?): Verify correct end date is calculated after membership
+ * renewal Failed asserting that two strings are equal.
+ * Expected-'2021-03-01' Actual+'2021-02-28'
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testRenewMembership() {
+ public function testRenewMembership(): void {
$contactId = $this->individualCreate();
$joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -6 month"));
$endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day"));
$membership['id'],
'id',
'membership_id',
- 'Database checked on membershiplog record.'
+ 'Database checked on membership log record.'
);
// this is a test and we dont want qfKey generation / validation
$config->keyDisable = TRUE;
$isTestMembership = 0;
- list($MembershipRenew) = CRM_Member_BAO_Membership::processMembership(
+ [$MembershipRenew] = CRM_Member_BAO_Membership::processMembership(
$contactId,
$this->_membershipTypeID,
$isTestMembership,
$MembershipRenew->id,
'id',
'membership_id',
- 'Database checked on membershiplog record.'
+ 'Database checked on membership log record.'
);
$this->assertEquals($this->_membershipTypeID, $MembershipRenew->membership_type_id, 'Verify membership type is changed during renewal.');
$this->assertEquals($endDate, $MembershipRenew->end_date, 'Verify correct end date is calculated after membership renewal');
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public function testStaleMembership() {
+ public function testStaleMembership(): void {
$statusId = 3;
$contactId = $this->individualCreate();
$joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -1 year -15 days"));
'Database checked on membership log record.'
);
- list($MembershipRenew) = CRM_Member_BAO_Membership::processMembership(
+ [$MembershipRenew] = CRM_Member_BAO_Membership::processMembership(
$contactId,
$this->_membershipTypeID,
FALSE,
$this->contactDelete($contactId);
}
- public function testUpdateAllMembershipStatusConvertExpiredOverriddenStatusToNormal() {
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testUpdateAllMembershipStatusConvertExpiredOverriddenStatusToNormal(): void {
$params = [
'contact_id' => $this->individualCreate(),
'membership_type_id' => $this->_membershipTypeID,
- 'join_date' => date('Ymd', time()),
- 'start_date' => date('Ymd', time()),
+ 'join_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
'end_date' => date('Ymd', strtotime('+1 year')),
'source' => 'Payment',
'is_override' => 1,
$this->assertArrayNotHasKey('status_override_end_date', $membershipAfterProcess);
}
- public function testUpdateAllMembershipStatusHandleOverriddenWithEndOverrideDateEqualTodayAsExpired() {
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testUpdateAllMembershipStatusHandleOverriddenWithEndOverrideDateEqualTodayAsExpired(): void {
$params = [
'contact_id' => $this->individualCreate(),
'membership_type_id' => $this->_membershipTypeID,
- 'join_date' => date('Ymd', time()),
- 'start_date' => date('Ymd', time()),
+ 'join_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
'end_date' => date('Ymd', strtotime('+1 year')),
'source' => 'Payment',
'is_override' => 1,
- 'status_override_end_date' => date('Ymd', time()),
+ 'status_override_end_date' => date('Ymd'),
'status_id' => $this->_membershipStatusID,
];
$this->assertArrayNotHasKey('status_override_end_date', $membershipAfterProcess);
}
- public function testUpdateAllMembershipStatusDoesNotConvertOverridenMembershipWithoutEndOverrideDateToNormal() {
+ /**
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testUpdateAllMembershipStatusDoesNotConvertOverriddenMembershipWithoutEndOverrideDateToNormal(): void {
$params = [
'contact_id' => $this->individualCreate(),
'membership_type_id' => $this->_membershipTypeID,
- 'join_date' => date('Ymd', time()),
- 'start_date' => date('Ymd', time()),
+ 'join_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
'end_date' => date('Ymd', strtotime('+1 year')),
'source' => 'Payment',
'is_override' => 1,
$createdMembershipID = $this->callAPISuccess('Membership', 'create', $params)['id'];
- civicrm_api3('Job', 'process_membership');
+ $this->callAPISuccess('Job', 'process_membership');
$membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
/**
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testMembershipPaymentForSingleContributionMultipleMembership() {
+ public function testMembershipPaymentForSingleContributionMultipleMembership(): void {
$membershipTypeID1 = $this->membershipTypeCreate(['name' => 'Parent']);
$membershipTypeID2 = $this->membershipTypeCreate(['name' => 'Child']);
$financialTypeId = $this->getFinancialTypeId('Member Dues');
'contact_id' => $this->individualCreate(),
'membership_type_id' => $membershipTypeID2,
'contribution_recur_id' => $contributionRecur['id'],
- 'join_date' => date('Ymd', time()),
- 'start_date' => date('Ymd', time()),
+ 'join_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
'end_date' => date('Ymd', strtotime('+1 year')),
'source' => 'Payment',
];
'contact_id' => $this->individualCreate(),
'membership_type_id' => $membershipTypeID2,
'contribution_recur_id' => $contributionRecur['id'],
- 'join_date' => date('Ymd', time()),
- 'start_date' => date('Ymd', time()),
+ 'join_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
'end_date' => date('Ymd', strtotime('+1 year')),
'source' => 'Payment',
];
'contact_id' => $parentContactId,
'membership_type_id' => $membershipTypeID1,
'contribution_recur_id' => $contributionRecur['id'],
- 'join_date' => date('Ymd', time()),
- 'start_date' => date('Ymd', time()),
+ 'join_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
'end_date' => date('Ymd', strtotime('+1 year')),
'skipLineItem' => TRUE,
'source' => 'Payment',
*
* @throws \CiviCRM_API3_Exception
*/
- public function testBuildMembershipTypeValues() {
+ public function testBuildMembershipTypeValues(): void {
$this->restoreMembershipTypes();
$form = new CRM_Core_Form();
$values = CRM_Member_BAO_Membership::buildMembershipTypeValues($form);
* https://lab.civicrm.org/dev/core/-/issues/1854
*
* @throws \CRM_Core_Exception
+ * @throws \Exception
*/
- public function testMembershipUpdateDoesNotDeleteRelatedMembershipsByMistake() {
+ public function testMembershipUpdateDoesNotDeleteRelatedMembershipsByMistake(): void {
$membershipOrganizationId = $this->organizationCreate();
$employerId = $this->organizationCreate();
'is_active' => 1,
]);
}
- $this->deleteRelatedMemberhsips($membership["id"]);
+ $this->deleteRelatedMemberships($membership["id"]);
$this->assertEquals(0, $this->getRelatedMembershipsCount($membership["id"]), 'Related membership count should be 0.');
// Create related memberships for first and last contact.
$this->assertEquals(2, $this->getRelatedMembershipsCount($membership["id"]), 'Related membership count should be 2.');
// Reset statics.
- unset(\Civi::$statics[CRM_Member_BAO_Membership::class]['related_contacts']);
+ unset(Civi::$statics[CRM_Member_BAO_Membership::class]['related_contacts']);
// Update membership by changing its status.
- $otherStatusID = $this->membershipStatusCreate('another status ' . rand(1, 1000));
+ $otherStatusID = $this->membershipStatusCreate('another status ' . random_int(1, 1000));
$membership["status_id"] = $otherStatusID;
$this->callAPISuccess("Membership", "create", $membership);
$this->assertMembershipExists($relatedMembership1['id']);
$this->assertMembershipExists($relatedMembership2['id']);
- // Clean up: Delete exerything!
- $this->membershipDelete($membership["id"]);
+ // Clean up: Delete everything!
+ $this->membershipDelete($membership['id']);
$this->membershipStatusDelete($otherStatusID);
}
* @param int $count
*
* @return array
- * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- private function createContacts($count) {
+ private function createContacts(int $count): array {
$contacts = [];
for ($i = 0; $i < $count; $i++) {
$contacts[] = $this->individualCreate();
*
* @throws \CRM_Core_Exception
*/
- private function deleteRelatedMemberhsips($parentMembershipID) {
- $memberships = $this->callAPISuccess("Membership", "get", [
+ private function deleteRelatedMemberships(int $parentMembershipID): void {
+ $this->callAPISuccess('Membership', 'get', [
'owner_membership_id' => $parentMembershipID,
'api.Membership.delete' => ['id' => '$value.id'],
]);
* @return array
* @throws \CRM_Core_Exception
*/
- private function createRelatedMembershipForContact($contactID, $parentMembership) {
- $membership = $this->callAPISuccess("Membership", "create", [
- 'membership_type_id' => $parentMembership["membership_type_id"],
+ private function createRelatedMembershipForContact(int $contactID, array $parentMembership): array {
+ return $this->callAPISuccess('Membership', 'create', [
+ 'membership_type_id' => $parentMembership['membership_type_id'],
'contact_id' => $contactID,
'status_id' => $this->_membershipStatusID,
'owner_membership_id' => $parentMembership['id'],
]);
-
- return $membership;
}
/**
* Checks the given membership ID can be found.
*
- * @param $membershipID
+ * @param int $membershipID
*
* @throws \CRM_Core_Exception
*/
- private function assertMembershipExists($membershipID) {
+ private function assertMembershipExists(int $membershipID): void {
$membership = $this->callAPISuccess("Membership", "get", [
'id' => $membershipID,
]);