acc-create-mock-repository
1
总安装量
1
周安装量
#44946
全站排名
安装命令
npx skills add https://github.com/dykyi-roman/awesome-claude-code --skill acc-create-mock-repository
Agent 安装分布
opencode
1
claude-code
1
Skill 文档
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
declare(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
- Use
-
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