<< All versions
Skill v1.0.1
currentAutomated scan100/100dykyi-roman/awesome-claude-code/create-mock-repository
4 files
──Details
PublishedAugust 27, 2026 at 04:29 AM
Content Hashsha256:7a16f2bde7434d39...
Git SHA7e1fea8899b7
Bump Typepatch
──Files
Files (1 file, 2.6 KB)
SKILL.md2.6 KBactive
SKILL.md · 103 lines · 2.6 KB
version: "1.0.1" name: create-mock-repository description: Generates InMemory repository implementations for PHP 8.4 testing. Creates fake repositories with array storage, supporting CRUD operations and queries without database.
Mock Repository Generator
Generates InMemory (Fake) repository implementations for testing.
Characteristics
- No database — stores entities in memory
- Fast — no I/O operations
- Isolated — fresh state per test
- Deterministic — predictable behavior
- Implements interface — same contract as real repository
Template
php
<?phpdeclare(strict_types=1);namespace Tests\Fake;use {RepositoryInterface};use {Entity};use {EntityId};final class InMemory{Entity}Repository implements {RepositoryInterface}{/** @var array<string, {Entity}> */private array $entities = [];public function save({Entity} $entity): void{$this->entities[$entity->id()->toString()] = $entity;}public function findById({EntityId} $id): ?{Entity}{return $this->entities[$id->toString()] ?? null;}public function delete({Entity} $entity): void{unset($this->entities[$entity->id()->toString()]);}/** @return list<{Entity}> */public function findAll(): array{return array_values($this->entities);}public function clear(): void{$this->entities = [];}}
Generation Instructions
- Read the repository interface:
- Extract all method signatures
- Identify entity type
- Identify ID type
- Generate InMemory implementation:
- Array storage keyed by ID
- Implement all interface methods
- Add
clear()for test cleanup
- Handle complex queries:
- Use
array_filterfor criteria - Support specifications if used
- Implement pagination with
array_slice
- Add test helpers (optional):
getAll()— access internal statehas(Id $id)— check existencecount()— entity count
- File placement:
tests/Fake/InMemory{Entity}Repository.php- Or
tests/Double/directory
Best Practices
- Match interface exactly — same method signatures
- Isolate per test — use
clear()in tearDown - Avoid complexity — simple in-memory logic
- Document deviations — if behavior differs from real impl
- Consider thread safety — for parallel tests (usually not needed)
References
references/examples.md— Complete repository examples (User, Order, Product)references/other-fakes.md— EventDispatcher, Mailer, Clock fakes