Skip to content

Commit 3e07fc1

Browse files
(Added) Enhance mutation testing coverage with logical condition tests (#49)
* test(mutation): Add comprehensive logical condition tests - Add Mac/Mc prefix handling tests targeting LogicalAnd mutations - Implement single character optimisation tests for mutation coverage - Test edge cases where both conditions must be true for code paths - Verify proper handling of array vs string parameter combinations - Enhance test coverage for logical operators in nameFix and strReplace These tests specifically target mutation testing scenarios by validating that logical AND conditions work correctly. The new test methods ensure that both conditions in logical expressions must be satisfied for the intended behaviour to occur, improving the robustness of mutation testing coverage. Signed-off-by: Marjo van Lier <marjo.vanlier@gmail.com> * chore: Enable manual approval for PR-Agent - Disable enable_auto_approval setting - Add require_approval = true configuration - Remove auto_approve commands from pr_commands and push_commands - PR-Agent will now require manual approval instead of automatic approval Co-authored-by: Marjo <MarjovanLier@users.noreply.github.com> --------- Signed-off-by: Marjo van Lier <marjo.vanlier@gmail.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Marjo <MarjovanLier@users.noreply.github.com>
1 parent a1c6432 commit 3e07fc1

3 files changed

Lines changed: 79 additions & 3 deletions

File tree

.pr_agent.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ require_all_thresholds_for_incremental_review = false
1111
minimal_commits_for_incremental_review = 2
1212
minimal_minutes_for_incremental_review = 10
1313
enable_help_text = false
14-
enable_auto_approval = true
14+
enable_auto_approval = false
15+
require_approval = true
1516
maximal_review_effort = 5
1617

1718
[pr_code_suggestions]
@@ -34,7 +35,7 @@ pr_commands = [
3435
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
3536
"/update_changelog --pr_update_changelog.push_changelog_changes=false",
3637
"/improve --extended --pr_code_suggestions.summarize=true",
37-
"/review auto_approve --pr_reviewer.num_code_suggestions=0 --pr_reviewer.inline_code_comments=true",
38+
"/review --pr_reviewer.num_code_suggestions=0 --pr_reviewer.inline_code_comments=true",
3839
]
3940
push_commands = [
4041
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
@@ -53,6 +54,6 @@ push_commands = [
5354
--pr_reviewer.minimal_minutes_for_incremental_review=10 \
5455
--pr_reviewer.extra_instructions='' \
5556
""",
56-
"/review auto_approve --pr_reviewer.num_code_suggestions=0 --pr_reviewer.inline_code_comments=true"
57+
"/review --pr_reviewer.num_code_suggestions=0 --pr_reviewer.inline_code_comments=true"
5758
]
5859
handle_push_trigger = true

tests/Unit/NameFixTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,38 @@ public function testNameFixWithNumericInput(): void
8080
{
8181
self::assertEquals('12345', StringManipulation::nameFix('12345'));
8282
}
83+
84+
85+
/**
86+
* Test that Mac/Mc prefix handling requires both conditions to be true.
87+
* This targets the LogicalAnd mutations in the nameFix function.
88+
*/
89+
public function testMacMcPrefixHandlingLogicalConditions(): void
90+
{
91+
// Test cases where 'mc' exists but is followed by a space (should NOT trigger fix)
92+
self::assertEquals('Mc Donald', StringManipulation::nameFix('mc donald'));
93+
self::assertEquals('Mc Lean', StringManipulation::nameFix('mc lean'));
94+
95+
// Test cases where 'mac' exists but is followed by a space (should NOT trigger fix)
96+
self::assertEquals('Mac Donald', StringManipulation::nameFix('mac donald'));
97+
self::assertEquals('Mac Lean', StringManipulation::nameFix('mac lean'));
98+
99+
// Test cases where 'mc' exists and is NOT followed by a space (SHOULD trigger fix)
100+
self::assertEquals('McDonald', StringManipulation::nameFix('mcdonald'));
101+
self::assertEquals('McLean', StringManipulation::nameFix('mclean'));
102+
103+
// Test cases where 'mac' exists and is NOT followed by a space (SHOULD trigger fix)
104+
self::assertEquals('MacDonald', StringManipulation::nameFix('macdonald'));
105+
self::assertEquals('MacLean', StringManipulation::nameFix('maclean'));
106+
107+
// Test cases where prefix doesn't exist at all
108+
self::assertEquals("O'brien", StringManipulation::nameFix("o'brien"));
109+
self::assertEquals('Johnson', StringManipulation::nameFix('johnson'));
110+
111+
// Test complex cases with multiple occurrences
112+
self::assertEquals('MacDonald-McDonald', StringManipulation::nameFix('macdonald-mcdonald'));
113+
114+
// Test edge case where both conditions in OR would be true but should only trigger once
115+
self::assertEquals('MacDonald Mac Smith', StringManipulation::nameFix('macdonald mac smith'));
116+
}
83117
}

tests/Unit/StrReplaceTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,47 @@ public function testEmptyStringOptimisation(): void
127127
}
128128

129129

130+
/**
131+
* Test that verifies both conditions are required for single character optimisation.
132+
* This targets the LogicalAnd mutations in the strReplace function.
133+
*/
134+
public function testSingleCharacterOptimisationRequiresBothConditions(): void
135+
{
136+
// Use variables to avoid Psalm's literal string analysis
137+
$testString = 'banana';
138+
$searchChar = 'a';
139+
$replaceChar = 'z';
140+
$expectedResult = 'bznznz';
141+
142+
// Case 1: Array search with single character - should NOT use strtr optimisation
143+
$result1 = StringManipulation::strReplace([$searchChar], $replaceChar, $testString);
144+
self::assertSame($expectedResult, $result1);
145+
146+
// Case 2: Array types - should NOT use strtr optimisation
147+
$result2 = StringManipulation::strReplace([$searchChar], [$replaceChar], $testString);
148+
self::assertSame($expectedResult, $result2);
149+
150+
// Case 3: Both string types but length > 1 - should NOT use strtr optimisation
151+
$result3 = StringManipulation::strReplace('an', $replaceChar, $testString);
152+
self::assertSame('bzza', $result3);
153+
154+
// Case 4: Both conditions met - SHOULD use strtr optimisation
155+
$result4 = StringManipulation::strReplace($searchChar, $replaceChar, $testString);
156+
self::assertSame($expectedResult, $result4);
157+
158+
// Case 5: Test empty string case - should NOT use strtr optimisation
159+
$result5 = StringManipulation::strReplace('', $replaceChar, $testString);
160+
self::assertSame($testString, $result5);
161+
162+
// Case 6: Test longer string case - should NOT use strtr optimisation
163+
$result6 = StringManipulation::strReplace('ban', 'can', $testString);
164+
self::assertSame('canana', $result6);
165+
166+
// All single-character replacements tested above should produce consistent results
167+
// The individual assertions above verify that different code paths work correctly
168+
}
169+
170+
130171
/**
131172
* Test comprehensive array-based string replacements.
132173
*/

0 commit comments

Comments
 (0)