Awesome-claude-code detect-test-smells

Detects test antipatterns and code smells in PHP test suites. Identifies 15 smells (Logic in Test, Mock Overuse, Fragile Tests, Mystery Guest, etc.) with fix recommendations and refactoring patterns for testability.

install
source · Clone the upstream repo
git clone https://github.com/dykyi-roman/awesome-claude-code
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/dykyi-roman/awesome-claude-code "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/detect-test-smells" ~/.claude/skills/dykyi-roman-awesome-claude-code-detect-test-smells && rm -rf "$T"
manifest: skills/detect-test-smells/SKILL.md
source content

Test Smell Detection

Identifies antipatterns and code smells in PHP test suites.

15 Test Smells

#SmellSeverityDetection Pattern
1Logic in TestHigh
if/for/while/foreach
in tests
2Mock OveruseHigh>3 mocks in single test
3Test InterdependenceHigh
static $
,
@depends
4Fragile TestHigh
expects(exactly)
,
at()
5Mystery GuestMedium
file_get_contents
,
getenv
6Eager TestMediumMultiple unrelated assertions
7Assertion RouletteMedium>5 assertions without context
8Obscure TestLow
test_it_works
,
test_foo
9Test Code DuplicationMediumRepeated setup/assertion
10Conditional Test LogicMedium
if.*assert
patterns
11Hard-Coded Test DataLowMagic values in tests
12Testing Private MethodsHigh
setAccessible(true)
13Slow TestMedium
sleep
, I/O in unit tests
14Mocking Final ClassesHighMock concrete final classes
15Mocking Value ObjectsHighMock readonly/immutable classes

Quick Detection Commands

# Logic in tests
Grep: "if \(|for \(|while \(|foreach \(" --glob "tests/**/*Test.php"

# Mock overuse (manual count needed)
Grep: "createMock|createStub" --glob "tests/**/*Test.php"

# Test interdependence
Grep: "static \$|@depends" --glob "tests/**/*Test.php"

# Testing private methods
Grep: "setAccessible\(true\)|ReflectionMethod" --glob "tests/**/*Test.php"

# Mystery guest
Grep: "file_get_contents|fopen|getenv|_ENV|_SERVER" --glob "tests/**/*Test.php"

# Fragile tests
Grep: "expects\(.*exactly|expects\(.*at\(" --glob "tests/**/*Test.php"

Output Format

# Test Smell Report

## Summary

| Smell | Count | Severity |
|-------|-------|----------|
| Logic in Test | 5 | High |
| Mock Overuse | 3 | High |

## Findings

### Logic in Test (5 occurrences)

| File | Line | Code |
|------|------|------|
| OrderTest.php | 45 | `foreach ($items as $item)` |

**Recommendation:** Extract to data providers or inline values.

## Action Items

1. **High Priority** — Refactor tests with >5 mocks
2. **Medium Priority** — Inline fixture data

Severity Matrix

SeveritySmellsImpact
HighLogic in Test, Mock Overuse, Test Interdependence, Fragile Test, Mocking Final/VO, Testing PrivateUnreliable results, design problems
MediumMystery Guest, Eager Test, Slow Test, Conditional Logic, DuplicationHard to understand/maintain
LowObscure Test, Hard-Coded DataDocumentation/readability

Related Skills

SmellFix With
Mock Overuse
create-mock-repository
Mystery Guest
create-test-builder
Test Duplication
create-test-builder

References

  • references/smell-catalog.md
    — Full smell descriptions with code examples
  • references/refactoring-patterns.md
    — Refactoring patterns for testability