Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Livewire Fakeable Laravel Package

tomeasterbrook/livewire-fakeable

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Target Use Case: Ideal for local development acceleration in Livewire-heavy applications where mocking state is critical for iterative UI/UX testing without relying on real data sources (e.g., APIs, databases).
  • Non-Intrusive Design: Leverages Livewire’s mount() lifecycle hook, ensuring fake data is injected only locally and only if state is empty, preserving production behavior.
  • Faker Integration: Tight coupling with FakerPHP provides realistic, configurable fake data (e.g., users, posts, transactions) without manual mocking.
  • Limitation: Scope is strictly local development—no runtime toggling or environment-based activation (e.g., .env flags). Requires discipline to avoid committing fake data to version control.

Integration Feasibility

  • Low Barrier: Single Composer dependency with zero configuration for basic usage. Advanced customization (e.g., custom Faker providers) requires minimal setup.
  • Livewire 4+ Only: Hard dependency on Livewire 4’s mount() hook structure. Breaking change risk if upgrading Livewire major versions.
  • State Management: Works with public/protected properties but not private properties or computed attributes (e.g., @computed). Requires explicit property declaration.
  • Testing Impact: Can replace some unit test mocks for integration tests, but not a substitute for end-to-end testing with real data.

Technical Risk

  • False Sense of Security: Fake data may mask edge cases (e.g., validation errors, API rate limits) not present in production. Risk of untested assumptions in deployed code.
  • State Pollution: If not careful, fake data could leak into tests or CI pipelines (e.g., if .env isn’t properly configured). Mitigate with .gitignore for storage/framework/testing/ or CI exclusions.
  • Performance Overhead: Minimal, but Faker generation adds microseconds per component mount. Negligible for most apps but could matter in high-frequency component re-renders (e.g., SPAs with Livewire).
  • Dependency Bloat: Adds FakerPHP as a transitive dependency (~1MB). Justify based on developer productivity gains.

Key Questions

  1. Does the team prioritize local dev speed over test rigor?
    • If yes, this reduces boilerplate for mocking.
    • If no, consider manual mocking or factory-based seeding (e.g., Laravel’s Factory classes).
  2. How complex is the Livewire component state?
    • Simple properties (e.g., name, email) benefit most.
    • Nested objects/relationships may require custom Faker providers (adding complexity).
  3. Is Livewire 4+ a hard requirement?
    • If not, evaluate alternatives like Livewire Mock (if available).
  4. Will fake data interfere with CI/CD?
    • Requires environment checks (e.g., app()->environment('local')) to prevent fake data in tests/staging.
  5. Are there existing mocking strategies (e.g., Laravel Factories)?
    • Overlap may reduce ROI. Assess whether this replaces or complements current workflows.

Integration Approach

Stack Fit

  • Best For:
    • Laravel/Livewire monoliths with interactive UI components (e.g., dashboards, forms).
    • Teams using TDD/BDD but struggling with Livewire’s state management in tests.
    • Projects where real data is unavailable early (e.g., pre-API contracts).
  • Poor Fit:
    • Headless/Lambda-based Livewire apps (fake data may not reflect serverless constraints).
    • Highly dynamic state (e.g., WebSockets, real-time updates) where fake data becomes stale quickly.
    • Teams with strict separation of concerns (e.g., fake data in components violates clean architecture).

Migration Path

  1. Pilot Phase:
    • Start with 1–2 critical components (e.g., user profile, checkout form).
    • Compare dev time saved vs. manual mocking.
  2. Configuration:
    • Add to composer.json:
      composer require tomeasterbrook/livewire-fakeable --dev
      
    • Register in AppServiceProvider (if needed for global Faker customization):
      use TomEasterbrook\LivewireFakeable\Facades\Fakeable;
      Fakeable::extend('user', function () { ... });
      
  3. Component Adoption:
    • Annotate properties in Livewire components:
      use TomEasterbrook\LivewireFakeable\Fakeable;
      
      class UserProfile extends Component {
          public string $name;
          public string $email;
      
          #[Fakeable]
          public function mount() {
              // Fake data injected here (locally only)
          }
      }
      
  4. Environment Guardrails:
    • Add to .env:
      FAKEABLE_ENABLED=true  # Local only
      
    • Disable in CI/CD via .env.testing:
      FAKEABLE_ENABLED=false
      

Compatibility

  • Livewire: Hard dependency on Livewire 4+. Test with Livewire 5 if upgrading soon.
  • PHP: Requires PHP 8.0+ (for FakerPHP compatibility).
  • FakerPHP: Custom providers must align with Faker’s v1.9+ syntax.
  • Testing Frameworks: Works with Pest/Laravel Tests, but fake data won’t persist in test databases (use DatabaseMigrations or RefreshDatabase traits for real test data).

Sequencing

  1. Phase 1: Integrate into new Livewire components first.
  2. Phase 2: Retrofit legacy components with fakeable properties (prioritize high-impact pages).
  3. Phase 3: Extend with custom Faker providers for domain-specific data (e.g., fake()->product()).
  4. Phase 4: Explore automated fake data generation for tests (e.g., combine with Laravel Factories).

Operational Impact

Maintenance

  • Low Effort:
    • No database migrations or API contracts required.
    • Updates align with Livewire/FakerPHP minor versions.
  • Customization:
    • Override defaults via service provider or component-specific logic.
    • Example: Disable for specific components:
      #[Fakeable(enabled: false)]
      public string $sensitiveData;
      
  • Deprecation Risk:
    • If Livewire changes mount() behavior, package may need updates. Monitor Livewire’s RFCs.

Support

  • Debugging:
    • Fake data won’t appear in production, reducing support noise.
    • Use dd($this->state) to inspect real vs. fake values during development.
  • Documentation:
    • Internal docs should clarify:
      • Fake data is local-only.
      • Avoid committing fake data to version control.
    • Example README snippet:
      ## Fake Data Warning
      This component uses `livewire-fakeable` for local development. **Never rely on fake data in production or tests.**
      
  • Community:
    • No active maintainer (0 stars, single author). Risk if issues arise. Consider forking for critical fixes.

Scaling

  • Performance:
    • Negligible impact for <100 components. For larger apps:
      • Lazy-load Faker providers.
      • Cache generated fake data (e.g., fake()->persist()).
  • Team Adoption:
    • Onboarding: 10-minute setup per developer.
    • Resistance: Some may prefer manual mocking or factory-based seeding. Address with:
      • Demo showing time saved (e.g., "No more User::factory()->create() in mount()").
      • Pair programming sessions for reluctant team members.
  • Monorepo/Polyrepo:
    • Works in multi-package setups if Livewire components are isolated.

Failure Modes

Scenario Impact Mitigation
Fake data committed to repo Tests/CI fail unpredictably .gitignore storage/framework/
Production data overwritten None (local-only) N/A
Faker provider errors Component fails to mount Fallback to empty state or defaults
Livewire major version bump Package breaks Pin Livewire version in composer.json
Over-reliance on fake data Untested edge cases in prod Enforce manual test validation

Ramp-Up

  • Developer Onboarding:
    • Time: 15–30 minutes per developer.
    • Steps:
      1. Install package.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle