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

Phony Laravel Package

eloquent/phony

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Functional & Object Mocking: Supports both procedural (function-level stubs/spies) and OOP (class/method mocking), aligning well with Laravel’s hybrid architecture (e.g., Eloquent ORM, service containers, and procedural helpers like Str::, Arr::).
    • Advanced PHP Feature Support: Handles modern PHP constructs (generators, variadic args, return types, traits, final classes via proxies) critical for Laravel’s evolving ecosystem (e.g., PHP 8.1+ attributes, named arguments).
    • Verification Clarity: Detailed failure messages (e.g., diffs, color-coded output) improve debugging in Laravel’s complex dependency graphs (e.g., service providers, event listeners).
    • Test Framework Agnosticism: Integrates with PHPUnit (Laravel’s default), Kahlan, and Peridot, reducing vendor lock-in.
  • Weaknesses:

    • Archived Status: No active maintenance raises risks for Laravel’s long-term compatibility (e.g., PHP 8.3+ features, Laravel 11+ changes).
    • Lack of Laravel-Specific Features: No built-in support for Laravel’s service container (bind(), singleton()), Facades, or Blade templating mocks.
    • No Dependents: Zero adopters suggest niche appeal; may lack polish for Laravel’s scale (e.g., no async/queue mocking).

Integration Feasibility

  • Pros:

    • Composer Integration: Simple composer require eloquent/phony-phpunit for PHPUnit (Laravel’s default).
    • Minimal Boilerplate: Zero-config setup; works alongside Laravel’s existing test helpers (e.g., RefreshDatabase, MigrateFresh).
    • Mocking Complexity: Ideal for testing:
      • Service Providers: Mock register()/boot() methods.
      • Repositories/Patterns: Stub Eloquent models or DTOs.
      • Legacy Code: Mock procedural helpers (e.g., Cache::remember()).
    • Hybrid Testing: Combine with Laravel’s Mockery (if needed) for feature parity.
  • Cons:

    • No Native Laravel Support: Requires manual setup for container binding mocks (e.g., app()->bind()).
    • Potential Conflicts: May clash with Laravel’s built-in mocking (e.g., createMock() in PHPUnit) or testing utilities (e.g., Laravel\Sanctum\PersonalAccessToken).
    • Learning Curve: Syntax differs from Laravel’s Mockery (e.g., Phony::mock() vs. Mockery::mock()).

Technical Risk

  • High:
    • Deprecation Risk: Archived package may break with Laravel/PHP updates (e.g., PHP 8.3’s new features).
    • Testing Gaps: No support for:
      • Laravel Queues: Mocking dispatch() or delay() calls.
      • Events: Verifying event(new Event()) invocations.
      • HTTP Tests: Mocking Http::fake() or Route::fake() interactions.
    • Performance: Overhead from dynamic proxies may impact large test suites.
  • Mitigation:
    • Fork & Maintain: Adapt the package for Laravel (e.g., add AppServiceProvider mocking).
    • Hybrid Approach: Use Phony for complex mocks + Laravel’s built-in tools for simple cases.
    • CI Validation: Test against Laravel’s latest LTS + PHP versions pre-release.

Key Questions

  1. Compatibility:
    • Does Phony work with Laravel’s PHPUnit bridge (e.g., createApplication())?
    • Can it mock Laravel’s Illuminate\Contracts interfaces (e.g., Authenticatable)?
  2. Performance:
    • What’s the overhead of Phony vs. Mockery in Laravel’s test suite?
  3. Maintenance:
    • Are there Laravel-specific forks (e.g., spatie/phony-laravel)?
  4. Alternatives:
    • Would Mockery + custom extensions cover Phony’s gaps with less risk?
  5. Long-Term:
    • If adopted, how would we handle future Laravel/PHP updates?

Integration Approach

Stack Fit

  • Primary Use Cases:
    • Unit Testing: Mocking Eloquent models, repositories, or services (e.g., UserRepository).
    • Integration Testing: Stubbing external APIs (e.g., Http::post()) or database interactions.
    • Legacy Code: Testing procedural helpers (e.g., Str::slug()) or static methods.
  • Avoid For:
    • Feature Testing: Use Laravel’s HttpTests, FeatureTests, or Pest/Testbench.
    • Database Tests: Prefer DatabaseMigrations, DatabaseTransactions, or RefreshDatabase.

Migration Path

  1. Pilot Phase:
    • Replace 1–2 complex mocks in existing tests (e.g., a UserRepository mock).
    • Compare test execution time and failure clarity vs. current tools.
  2. Gradual Adoption:
    • Step 1: Use eloquent/phony-phpunit for new unit tests.
    • Step 2: Migrate legacy Mockery tests to Phony for procedural code.
    • Step 3: Extend Phony for Laravel-specific needs (e.g., service container mocks).
  3. Tooling:
    • Add a php-cs-fixer rule to standardize Phony syntax (e.g., mock() vs. createMock()).
    • Document Phony usage in the team’s testing guidelines.

Compatibility

Laravel Component Phony Support Workaround
Eloquent Models ✅ (Class mocking) Use mock('App\Models\User')
Service Container Manually stub app()->bind()
Facades (e.g., Cache::) Use Phony + Facade::swap()
HTTP Client (Http::) Stub Illuminate\Support\Facades\Http
Queues (Bus::fake()) Mock Illuminate\Bus\Dispatcher
Events (Event::fake()) Stub Illuminate\Events\Dispatcher
Blade Views Mock Illuminate\View\Factory
PHPUnit Bridge ✅ (via eloquent/phony-phpunit) Use Phony::mock() in tests

Sequencing

  1. Phase 1: Unit Tests
    • Replace Mockery for mocking classes/interfaces (e.g., UserRepository).
    • Example:
      // Before (Mockery)
      $mock = Mockery::mock(UserRepository::class);
      $mock->shouldReceive('find')->andReturn($user);
      
      // After (Phony)
      $handle = Phony::mock(UserRepository::class);
      $handle->find->returns($user);
      $repository = $handle->get();
      
  2. Phase 2: Procedural Code
    • Stub global functions (e.g., Str::slug()) or static methods.
    • Example:
      $handle = mock('Str');
      $handle->slug->with('test')->returns('test-slug');
      
  3. Phase 3: Integration Tests
    • Stub external dependencies (e.g., Http::post()) alongside Laravel’s Http::fake().
  4. Phase 4: Custom Extensions
    • Build Laravel-specific wrappers (e.g., PhonyLaravel::mockServiceProvider()).

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Phony’s fluent API may simplify complex mocks.
    • Consistent Syntax: Uniform approach across procedural/OOP code.
  • Cons:
    • Archived Package: Requires vigilance for breaking changes (e.g., PHP 8.3).
    • No Laravel Updates: Missing features (e.g., queue/event mocking) need manual workarounds.
    • Dependency Risk: If Phony breaks, tests may fail silently until discovered.

Support

  • Challenges:
    • Debugging: Unfamiliar error messages may slow down onboarding.
    • Tooling Gaps: Lack of IDE support (e.g., PhpStorm plugins for Phony).
    • Community: No active maintainer or Laravel-specific documentation.
  • Mitigation:
    • Internal Docs: Create a Phony cheat sheet for the team.
    • CI Checks: Add tests to detect Phony compatibility issues early.
    • Fallback Plan: Document how to revert to Mockery for critical tests.

**Scal

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.
besmartand-pro/php-quality-config
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views
spatie/ignition-contracts