maatify/data-fakes
Composer 安装命令:
composer require --dev maatify/data-fakes
包简介
Complete fake simulation layer for MySQL, DBAL, Redis, and Mongo adapters.
关键字:
README 文档
README
📘 Maatify Data Fakes
In-Memory Fake Adapters for MySQL, Redis, MongoDB & Repository Layer
Version: 1.0.4
Project: maatify/data-fakes
Maintained by: Maatify.dev
🚀 Overview
maatify/data-fakes is a deterministic, lightweight in-memory data simulation engine fully compatible with all official Maatify Data Adapters.
It allows any repository or service to run and be tested without any real databases, providing:
- Fake MySQL Adapter
- Fake MySQL DBAL Adapter
- Fake Redis Adapter
- Fake MongoDB Adapter
- Fake Repository Layer
- Unit of Work + Snapshot Engine (Phase 6)
- Fixtures Loader + FakeEnvironment (Phase 7)
- Advanced Simulation Layer: Latency + Failure Injection (Phase 8)
- Fully deterministic test isolation
- Zero external services required — perfect for CI
All Fake Adapters follow the exact same contracts used by real adapters across the Maatify ecosystem.
🔑 Core Dependencies
The core of the library is built on:
-
AdapterInterface
Maatify\Common\Contracts\Adapter\AdapterInterface -
ResolverInterface
Maatify\DataAdapters\Contracts\ResolverInterface
Every Fake Adapter implements AdapterInterface and is routed through ResolverInterface to ensure 1:1 behavior with real adapters.
🧩 Features
🗄️ Storage Features
- Fully in-memory storage layer
- Auto-increment & mixed ID handling
- Snapshot export/import (Phase 6)
- Deterministic state across tests
🔍 Query Features
- SQL-like filtering (where/in/like/order/limit)
- Mongo-like operators (
$in,$gt,$lte,$ne, …) - Redis-like operations (list, hash, strings, counters, TTL)
🧱 Repository Layer
- FakeRepository
- FakeCollection
- ArrayHydrator
🔄 Unit of Work (Phase 6)
- Nested transactions
- Snapshot-based rollback
- Transactional wrapper
- Fully deterministic
📦 Fixtures & Environment (Phase 7)
- JSON / array fixtures loader
- SQL + Mongo + Redis hydration
- FakeEnvironment with auto-reset
⚡ Advanced Simulation Layer (Phase 8)
Adds deterministic CI-safe fault injection:
🔹 ErrorSimulator
- Failure scenarios per operation
- Probability-based injection
- Deterministic exception throwing
🔹 LatencySimulator
- Per-operation latency
- Default latency
- Optional jitter
- Perfect for CI reproducibility
🔹 SimulationAwareTrait
Hooks used inside adapters:
guardOperation()- Latency simulation
- Failure simulation
📦 Installation
composer require maatify/data-fakes --dev
✔ Recommended for testing ✘ Not for production
🧪 Basic Usage
Using the Fake MySQL adapter
use Maatify\DataFakes\Adapters\MySQL\FakeMySQLAdapter; use Maatify\DataFakes\Storage\FakeStorageLayer; $storage = new FakeStorageLayer(); $mysql = new FakeMySQLAdapter($storage); $mysql->connect(); $mysql->insert('users', ['name' => 'Ada Lovelace']); $rows = $mysql->select('users', ['name' => 'Ada Lovelace']);
Reset Between Tests
$storage->reset();
📘 Usage Examples
All examples are available in: → docs/examples.md
📁 Fake Components Included
🗄️ Fake Adapters
- FakeMySQLAdapter
- FakeMySQLDbalAdapter
- FakeRedisAdapter
- FakeMongoAdapter
🧩 Repository Layer (Phase 5)
- FakeRepository
- FakeCollection
- ArrayHydrator
🔀 Routing
- FakeResolver
🔄 Unit of Work & Snapshots (Phase 6)
- FakeUnitOfWork
- SnapshotManager
- SnapshotState
📦 Fixtures & Environment (Phase 7)
- FakeFixturesLoader
- JsonFixtureParser
- FakeEnvironment
- ResetState
⚡ Simulation Layer (Phase 8)
- ErrorSimulator
- LatencySimulator
- FailureScenario
- SimulationAwareTrait
📚 Development Phases & Documentation Links
-
Phase 1 — Project Bootstrap & Core Architecture
docs/phases/README.phase1.md -
Phase 2 — Fake MySQL & DBAL Adapter
docs/phases/README.phase2.md -
Phase 3 — Fake Redis Adapter
docs/phases/README.phase3.md -
Phase 4 — Fake Mongo Adapter
docs/phases/README.phase4.md -
Phase 5 — Repository Layer
docs/phases/README.phase5.md -
Phase 6 — Snapshot Engine + Unit of Work
docs/phases/README.phase6.md -
Phase 7 — Fixtures Loader + FakeEnvironment
docs/phases/README.phase7.md -
Phase 8 — Advanced Simulation Layer (Latency + Failure Injection)
docs/phases/README.phase8.md
📝 Full Documentation
👉 README.full.md
Includes:
- Architecture
- Class reference
- API maps
- Fixtures & environments
- Snapshot behaviors
- Phase 1 → Phase 8 technical breakdown
🪪 License
MIT license © Maatify.dev
Free to use, modify, and distribute with attribution.
👤 Author
© 2025 Maatify.dev
Engineered by Mohamed Abdulalim (@megyptm)
https://www.maatify.dev
📘 Full documentation & source code:
https://github.com/Maatify/data-fakes
🤝 Contributors
Special thanks to the Maatify.dev engineering team and open-source contributors.
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries
maatify/data-fakes 适用场景与选型建议
maatify/data-fakes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 491 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「database」 「dbal」 「mongodb」 「php」 「testing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maatify/data-fakes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maatify/data-fakes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maatify/data-fakes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Microservice RPC through message queues.
Store your language lines in the database, yaml or other sources
The CodeIgniter Redis package
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A custom Doctine DBAL type to use PHP DateTime objects set to the system's default timezone.
统计信息
- 总下载量: 491
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-22