b29a268b1d
- Move completed plan files to .plans/done/ - Move 18 open plan files to .plans/open/ - Update .gitignore to exclude .verified_plans temp file - Verified all 18 open plans still describe unimplemented issues
2.8 KiB
2.8 KiB
Plan: Issue #45 — Unit tests for FeeCalculationService
Summary
Create comprehensive PHPUnit tests for FeeCalculationService covering all 13 test cases specified in the issue: single member fees, family discount tiers, frozen rates, Erziehungsberechtigter exclusion, manual overrides during batch, mixed family states, error handling for missing rules, and cross-year rule changes.
Implementation Steps
Step 1: Create phpunit.xml configuration
- Add
phpunit.xmlat project root with standard Nextcloud app test configuration - Configure autoloading to use composer PSR-4 paths
- Set test suite directory to
tests/Unit/
Step 2: Create test helper for building mock Members/Rules
- Create a helper trait or base class that provides factory methods:
createMember(id, rolle, status, familyId, geburtsdatum, frozenFeeRate)createFeeRule(yearFrom, baseRate, familyRulesJson, inactiveRule)createFeeRecord(memberId, year, amount, manuellAngepasst)
Step 3: Create FeeCalculationServiceTest.php
Write isolated test methods for each case in the issue:
testSingleMemberNoFamily— member without family_id → base_ratetestSingleChildInFamily— 1 active child → family rule "1" ratetestTwoChildrenInFamily— 2 active children → correct per-child amounts per positiontestThreeOrMoreChildrenInFamily— 3+ children → "3+" catch-all rule applied, additional children at that ratetestInactiveMemberWithFrozenRate— inactive member with frozen_fee_rate → frozen rate returnedtestErziehungsberechtigterExcluded— rolle=erziehungsberechtigter → fee = 0.00testManualOverrideSkippedDuringBatch— manuell_angepasst records not overwritten in batchCalculatetestMixedFamilyActiveInactiveChildren— only active children counted for position-based discounttestMemberBecomesInactiveMidYear— rate frozen at current valuetestNoFeeRuleForYear— DoesNotExistException throwntestRuleChangeBetweenYears— correct rule applied per yeartestEmptyFamilyNoChildren— no fees generated (base rate for adults in empty family)testMemberWithoutFamilyWithOverrideBanking— base rate
Step 4: Ensure all tests use mocked mappers
- Mock
FeeRuleMapper,FeeRecordMapper,MemberMapper - Mock
IUserSessionandLoggerInterface - Each test creates its own data set, no shared state
Acceptance Criteria Checklist
- AC1:
FeeCalculationServiceTest.phpexists intests/Unit/ - AC2: All 13 test cases from the issue are implemented
- AC3: Tests use mock data (mocked mappers), isolated per test
- AC4: Tests assert exact amounts and rule snapshots
- AC5: Tests cover both
calculateFee()andbatchCalculate()methods - AC6: phpunit.xml configuration is present