Skip to content

In-memory Fake Adapters for MySQL, Redis, and MongoDB — fully compatible with the Maatify Data Adapters ecosystem. Provides deterministic storage, DBAL simulation, TTL, filtering, and full test isolation for repositories and services.

License

Notifications You must be signed in to change notification settings

Maatify/data-fakes

Maatify.dev


Version PHP Build

Monthly Downloads Total Downloads

Stars License Status Code Quality

PHPStan Coverage

Changelog Security


📘 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:

  1. AdapterInterface Maatify\Common\Contracts\Adapter\AdapterInterface

  2. 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


📝 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

About

In-memory Fake Adapters for MySQL, Redis, and MongoDB — fully compatible with the Maatify Data Adapters ecosystem. Provides deterministic storage, DBAL simulation, TTL, filtering, and full test isolation for repositories and services.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages