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

Bridge Mockery Laravel Package

testo/bridge-mockery

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The testo/bridge-mockery package bridges Mockery (a PHP mocking library) with Testo (a lightweight PHP testing framework). This is valuable if the application relies on Testo for testing but requires Mockery for advanced mocking capabilities (e.g., partial mocks, mocking non-testable classes, or complex expectations).
  • Use Case Justification:
    • Ideal for legacy systems or projects where Testo is already adopted but lacks native mocking support.
    • Useful in monolithic PHP applications where replacing the testing framework is not feasible.
    • Less relevant for greenfield projects using PHPUnit or Pest, which have built-in mocking or native Mockery support.
  • Alternatives Consideration:
    • If the project uses PHPUnit, native mocking or mockery/mockery directly may suffice.
    • If Testo is the primary choice, evaluate whether its mocking limitations justify this bridge or if a framework switch is better long-term.

Integration Feasibility

  • Dependency Graph:
    • Requires Testo (testo/testo) and Mockery (mockery/mockery) as dependencies.
    • No major conflicts expected, but ensure version compatibility (e.g., Mockery 1.x vs. 2.x).
  • Codebase Impact:
    • Minimal changes needed if Testo is already in use. Tests using Mockery can be migrated incrementally.
    • May require refactoring test files to use the bridge’s API (e.g., Testo\Bridge\Mockery\MockeryTestCase).
  • Tooling Compatibility:
    • Works with PHPUnit test runners (if Testo is integrated via PHPUnit bootstrap).
    • May need adjustments for CI/CD pipelines if Mockery is newly introduced.

Technical Risk

  • Low-Medium Risk:
    • Versioning Risk: Mockery has undergone breaking changes (e.g., v1 → v2). Ensure the bridge supports the required Mockery version.
    • Maintenance Risk: With 0 stars/dependents, the package may lack active maintenance. Verify:
      • Last commit date.
      • Issue/PR response time (if any).
      • Compatibility with Testo’s latest version.
    • Testing Overhead: Bridging two frameworks may introduce edge cases in test execution (e.g., assertion conflicts, setup teardown issues).
  • Mitigation:
    • Start with a proof-of-concept in a non-critical module.
    • Monitor for upstream updates to Testo/Mockery that could break compatibility.

Key Questions

  1. Why Testo?
    • Is Testo used for specific reasons (e.g., performance, simplicity), or is it a legacy choice?
    • Could the project migrate to PHPUnit/Pest for better mocking support long-term?
  2. Mockery Necessity
    • Are there specific mocking features in Mockery that Testo lacks (e.g., mocking final classes, dynamic mocks)?
    • Could simpler alternatives (e.g., Testo’s built-in stubs) suffice?
  3. Team Familiarity
    • Is the team already comfortable with Mockery? If not, ramp-up time may increase.
  4. Long-Term Viability
    • What’s the plan if the bridge becomes unsupported or incompatible with future Testo/Mockery versions?
  5. Performance Impact
    • Does Mockery add significant overhead to test execution compared to native Testo mocking?

Integration Approach

Stack Fit

  • Target Environments:
    • PHP 8.0+ (verify compatibility; Mockery 2.x requires PHP 7.4+).
    • Testo 2.x+ (check bridge documentation for exact version support).
    • Composer-based projects (package is PSR-4 autoloadable).
  • Framework Synergy:
    • Works best in Testo-driven projects where Mockery is needed for:
      • Complex object interactions.
      • Mocking external services (e.g., APIs, databases) without full implementations.
    • Less ideal for:
      • Projects with no mocking needs beyond Testo’s capabilities.
      • Teams using BDD frameworks (e.g., Behat) where Mockery may not integrate cleanly.

Migration Path

  1. Assessment Phase:
    • Audit existing tests to identify Mockery-dependent scenarios.
    • Benchmark Testo’s native mocking against Mockery’s capabilities for the identified use cases.
  2. Incremental Adoption:
    • Step 1: Add testo/bridge-mockery and mockery/mockery to composer.json.
    • Step 2: Extend a Testo test case with Testo\Bridge\Mockery\MockeryTestCase:
      use Testo\Bridge\Mockery\MockeryTestCase;
      
      class MyTest extends MockeryTestCase {
          public function testSomething() {
              $mock = $this->mock('MyClass');
              // Mockery methods...
          }
      }
      
    • Step 3: Migrate tests one module at a time, verifying compatibility.
  3. Refactoring:
    • Replace Testo-specific mocking syntax with Mockery equivalents where needed.
    • Update test setup/teardown to handle Mockery’s expectations (e.g., $this->mockery->close()).

Compatibility

  • Version Alignment:
    • Cross-reference the bridge’s composer.json for supported Mockery/Testo versions.
    • Example: If the bridge only supports Mockery 1.x, ensure the project doesn’t require 2.x features.
  • Conflict Resolution:
    • Assertion Conflicts: Testo and Mockery may have overlapping assertion methods. Use namespacing (e.g., Mockery::mock() vs. Testo\assert()).
    • Global State: Mockery maintains a global container. Ensure tests don’t interfere via Mockery::close() or Mockery::disable().
  • IDE/Tooling:
    • Configure IDEs (PHPStorm, VSCode) to recognize Mockery’s PHPDoc annotations in Testo tests.
    • Update static analysis tools (e.g., Psalm, PHPStan) to account for Mockery’s dynamic nature.

Sequencing

  1. Pre-Integration:
    • Set up a dedicated branch for the migration.
    • Add Mockery to composer.json and run dependency checks:
      composer require --dev testo/bridge-mockery mockery/mockery
      
  2. Parallel Testing:
    • Run existing Testo tests to ensure no regressions.
    • Gradually rewrite tests to use the bridge, starting with low-risk modules.
  3. Post-Integration:
    • Update CI/CD pipelines to include Mockery’s test coverage (if applicable).
    • Document the bridge’s usage patterns for the team.

Operational Impact

Maintenance

  • Dependency Management:
    • Monitor Mockery and Testo for breaking changes that may affect the bridge.
    • Example: Mockery 2.x introduced changes to mock() syntax and expectations.
    • Action: Pin versions in composer.json or use ^ cautiously:
      "testo/bridge-mockery": "^1.0",
      "mockery/mockery": "~2.0"
      
  • Bridge-Specific Tasks:
    • Periodically check for updates to testo/bridge-mockery (even if inactive, forks or issues may emerge).
    • Maintain a runbook for common Mockery/Testo integration issues (e.g., "How to debug a failing mock expectation").

Support

  • Troubleshooting:
    • Common Issues:
      • Mockery not loading: Verify autoloader includes Testo\Bridge\Mockery.
      • Assertion failures: Ensure Mockery’s expectations are properly set up (e.g., shouldReceive() vs. shouldIgnore()).
      • Memory leaks: Use Mockery::close() in test teardown to avoid global state pollution.
    • Debugging Tools:
      • Mockery’s --show-unmockable flag to identify unmockable classes.
      • Testo’s --verbose flag for detailed test output.
  • Team Onboarding:
    • Create a cheat sheet comparing Testo’s mocking to Mockery’s (e.g., Testo’s stub() vs. Mockery’s mock()).
    • Conduct a workshop to align the team on the bridge’s patterns.

Scaling

  • Performance:
    • Mockery Overhead: Mockery’s dynamic proxies may add slight runtime overhead during tests. Profile with:
      composer require --dev phpbench/phpbench
      
    • Parallelization: Mockery’s global state can cause issues in parallel test runners (e.g., PHPUnit’s --parallel). Use --group or isolate mocks per test.
  • Test Suite Growth:
    • As the test suite grows, ensure Mockery’s memory usage doesn’t become a bottleneck. Use:
      // In setUp()
      $this->mockery->disableOriginalClone();
      
    • Consider **
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
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