maatify/data-fakes

Complete fake simulation layer for MySQL, DBAL, Redis, and Mongo adapters.

Installs: 331

Dependents: 2

Suggesters: 1

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/maatify/data-fakes

v1.0.4 2025-11-23 08:46 UTC

This package is auto-updated.

Last update: 2025-11-24 09:33:28 UTC


README

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