DefaultOfficerManagerTest
extends BaseTestCase
in package
Officers\Services\DefaultOfficerManager Test Case
Tests the DefaultOfficerManager service including the new recalculateOfficersForOffice functionality for office configuration changes.
Tags
Table of Contents
Constants
- TEST_MEMBER_ID = self::ADMIN_MEMBER_ID
- Test member ID for testing
- TEST_OFFICE_ID = 1
- Test office ID for testing
- TEST_UPDATER_ID = self::ADMIN_MEMBER_ID
- Test updater ID
Properties
- $Branches : BranchesTable
- Branches table
- $MemberRoles : MemberRolesTable
- MemberRoles table
- $Members : MembersTable
- Members table
- $officerManager : OfficerManagerInterface
- Service under test
- $Officers : OfficersTable
- Officers table
- $Offices : OfficesTable
- Offices table
- $Roles : RolesTable
- Roles table
- $testBranch : Branch
- Test branch entity
- $testBranchId : int
- Test branch ID
Methods
- testAssignCalculatesEndDateFromTermLength() : void
- Test assignment calculates end date from term_length when not provided
- testAssignNonWarrantableMemberToWarrantRequiredOfficeFails() : void
- Test assignment to office requiring warrant for non-warrantable member fails
- testAssignOfficerSuccessfully() : void
- Test successful assignment of officer to office without warrant requirement
- testRecalculateOfficersForOfficeExcludesExpiredOfficers() : void
- Test recalculateOfficersForOffice excludes expired officers
- testRecalculateOfficersForOfficeFailFastOnSaveFailure() : void
- Test recalculateOfficersForOffice fail-fast on officer save failure
- testRecalculateOfficersForOfficeWithDeputyToChange() : void
- Test recalculateOfficersForOffice with deputy_to_id change
- testRecalculateOfficersForOfficeWithNoOfficers() : void
- Test recalculateOfficersForOffice with no officers
- testRecalculateOfficersForOfficeWithReportsToChange() : void
- Test recalculateOfficersForOffice with reports_to_id change
- testRecalculateOfficersForOfficeWithRoleAdded() : void
- Test recalculateOfficersForOffice with grants_role_id added
- testRecalculateOfficersForOfficeWithRoleChanged() : void
- Test recalculateOfficersForOffice with grants_role_id changed
- testRecalculateOfficersForOfficeWithRoleRemoved() : void
- Test recalculateOfficersForOffice with grants_role_id removed
- testReleaseOfficerSuccessfully() : void
- Test successful release of officer
- testReleaseOfficerWithReplacedStatus() : void
- Test release with custom status (REPLACED_STATUS)
- setUp() : void
- setUp method
- tearDown() : void
- tearDown method
Constants
TEST_MEMBER_ID
Test member ID for testing
private
mixed
TEST_MEMBER_ID
= self::ADMIN_MEMBER_ID
TEST_OFFICE_ID
Test office ID for testing
private
mixed
TEST_OFFICE_ID
= 1
TEST_UPDATER_ID
Test updater ID
private
mixed
TEST_UPDATER_ID
= self::ADMIN_MEMBER_ID
Properties
$Branches
Branches table
protected
BranchesTable
$Branches
$MemberRoles
MemberRoles table
protected
MemberRolesTable
$MemberRoles
$Members
Members table
protected
MembersTable
$Members
$officerManager
Service under test
protected
OfficerManagerInterface
$officerManager
$Officers
Officers table
protected
OfficersTable
$Officers
$Offices
Offices table
protected
OfficesTable
$Offices
$Roles
Roles table
protected
RolesTable
$Roles
$testBranch
Test branch entity
protected
Branch
$testBranch
$testBranchId
Test branch ID
private
static int
$testBranchId
Methods
testAssignCalculatesEndDateFromTermLength()
Test assignment calculates end date from term_length when not provided
public
testAssignCalculatesEndDateFromTermLength() : void
Uses Kingdom Earl Marshal (office ID 2) which has a 24-month term
testAssignNonWarrantableMemberToWarrantRequiredOfficeFails()
Test assignment to office requiring warrant for non-warrantable member fails
public
testAssignNonWarrantableMemberToWarrantRequiredOfficeFails() : void
NOTE: This test is marked incomplete because warrantable is a virtual calculated
field based on multiple factors (background check, membership status, etc.), not a
simple database column that can be directly set. To properly test this scenario,
we would need to set up all the conditions that make a member non-warrantable
(expired background check, expired membership, etc.).
The validation logic IS present in DefaultOfficerManager::assign() lines 228-233, which checks if office requires_warrant and member is not warrantable.
testAssignOfficerSuccessfully()
Test successful assignment of officer to office without warrant requirement
public
testAssignOfficerSuccessfully() : void
Uses existing seed data:
- Member ID 1 (Admin von Admin)
- Office ID 1 (Crown - no warrant required)
- Creates a test branch since branches table is empty in seed
testRecalculateOfficersForOfficeExcludesExpiredOfficers()
Test recalculateOfficersForOffice excludes expired officers
public
testRecalculateOfficersForOfficeExcludesExpiredOfficers() : void
Officers with expired status should not be recalculated (preserve history).
testRecalculateOfficersForOfficeFailFastOnSaveFailure()
Test recalculateOfficersForOffice fail-fast on officer save failure
public
testRecalculateOfficersForOfficeFailFastOnSaveFailure() : void
When an officer save fails, the method should return error immediately without processing remaining officers.
testRecalculateOfficersForOfficeWithDeputyToChange()
Test recalculateOfficersForOffice with deputy_to_id change
public
testRecalculateOfficersForOfficeWithDeputyToChange() : void
When an office's deputy_to_id changes, all deputy officers should have their deputy_to and reports_to relationships recalculated.
testRecalculateOfficersForOfficeWithNoOfficers()
Test recalculateOfficersForOffice with no officers
public
testRecalculateOfficersForOfficeWithNoOfficers() : void
When an office has no current or upcoming officers, recalculation should succeed with zero updates.
testRecalculateOfficersForOfficeWithReportsToChange()
Test recalculateOfficersForOffice with reports_to_id change
public
testRecalculateOfficersForOfficeWithReportsToChange() : void
When an office's reports_to_id changes, all current and upcoming officers should have their reports_to_office_id and reports_to_branch_id recalculated.
testRecalculateOfficersForOfficeWithRoleAdded()
Test recalculateOfficersForOffice with grants_role_id added
public
testRecalculateOfficersForOfficeWithRoleAdded() : void
When an office starts granting a role, all current and upcoming officers should receive the new member role.
testRecalculateOfficersForOfficeWithRoleChanged()
Test recalculateOfficersForOffice with grants_role_id changed
public
testRecalculateOfficersForOfficeWithRoleChanged() : void
When an office changes which role it grants, officers should have the old role ended and a new role created.
testRecalculateOfficersForOfficeWithRoleRemoved()
Test recalculateOfficersForOffice with grants_role_id removed
public
testRecalculateOfficersForOfficeWithRoleRemoved() : void
When an office stops granting a role, all current and upcoming officers should have their member roles ended.
testReleaseOfficerSuccessfully()
Test successful release of officer
public
testReleaseOfficerSuccessfully() : void
First assigns an officer, then releases them
testReleaseOfficerWithReplacedStatus()
Test release with custom status (REPLACED_STATUS)
public
testReleaseOfficerWithReplacedStatus() : void
Assigns an officer then releases with "replaced" status
setUp()
setUp method
protected
setUp() : void
tearDown()
tearDown method
protected
tearDown() : void