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

Phiremock Client Laravel Package

mcustiel/phiremock-client

PHP client for Phiremock Server with a fluent API to define HTTP expectations, manage scenarios, and reset server state. Works with Guzzle 6 by default, or any PSR-18 HTTP client by overriding the factory for custom connections.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Fluent API for HTTP Mocking: The package provides a clean, expressive syntax for defining expectations, scenarios, and responses, which aligns well with Laravel’s testing and API development needs (e.g., unit/integration tests, contract testing, or mocking external services).
  • JSON Path Support: Enables advanced querying of nested JSON structures (e.g., validating API responses, extracting data from complex payloads), reducing manual parsing and improving maintainability. This is particularly valuable for Laravel applications interacting with GraphQL, SaaS APIs, or microservices.
  • PSR-18 Compatibility: Leverages modern PHP standards (PSR-18 HTTP clients), ensuring flexibility to swap implementations (e.g., Guzzle, Symfony HTTP Client) without vendor lock-in. This is critical for Laravel’s evolving ecosystem (e.g., Symfony components integration).
  • Scenario Management: Supports stateful mocking (e.g., sequential API responses, conditional logic), which is essential for testing complex workflows (e.g., OAuth flows, multi-step transactions).
  • Laravel Synergy: The package’s design (e.g., fluent builders, helper functions) mirrors Laravel’s Eloquent query builder and service container patterns, reducing cognitive load for developers.

Integration Feasibility

  • High for Laravel Projects:
    • Testing: Seamlessly integrates with Laravel’s testing tools (e.g., Http::fake(), PestPHP, or PHPUnit) to mock HTTP clients (e.g., Guzzle, Symfony HTTP Client) without reinventing wheel.
    • API Development: Useful for stubbing external APIs during development or CI/CD pipelines (e.g., mocking Stripe, Twilio, or payment gateways).
    • Legacy System Replacement: Can replace custom mocking solutions or tools like VCR (for HTTP interactions) with a more maintainable, feature-rich alternative.
  • Moderate for Non-Laravel PHP:
    • Requires Laravel-specific patterns (e.g., service providers, facades) for deeper integration. Standalone PHP projects may need additional abstraction.
  • Risk:
    • Dependency Conflicts: Guzzle v6/v7 or PSR-18 client requirements may conflict with existing Laravel dependencies (e.g., http/guzzle vs. symfony/http-client). Mitigation: Use the package’s factory override to enforce consistency.
    • Learning Curve: Fluent API syntax may require onboarding for teams unfamiliar with Phiremock or similar tools (e.g., WireMock). Mitigation: Provide Laravel-specific documentation/examples.

Key Questions

  1. Use Case Alignment:
    • Does the project require dynamic HTTP mocking (e.g., testing API clients, simulating edge cases) or JSON Path querying (e.g., validating nested responses)?
    • Are you using Laravel 10+ (PHP 8.2+)? If not, can you upgrade, or is v1.x sufficient?
  2. Infrastructure Impact:
    • Will the package run alongside an existing Phiremock Server instance, or do you need to deploy it (e.g., Docker, local dev environments)?
    • How will you handle secure connections (HTTPS) and authentication (e.g., API keys) for the Phiremock Server?
  3. Testing Strategy:
    • Will this replace existing mocking tools (e.g., Laravel’s Http::fake())? If so, what’s the migration path for existing tests?
    • Do you need to mock WebSocket or gRPC interactions? (Note: Phiremock focuses on HTTP.)
  4. Maintenance:
    • Is the package’s GPL-3.0 license compatible with your project’s licensing (e.g., proprietary software)?
    • What’s the long-term support plan? The package has no dependents, so community adoption is unproven.
  5. Performance:
    • How will the additional HTTP layer (client ↔ Phiremock Server) impact test execution speed in CI/CD?
    • Are there memory/CPU overhead concerns for large-scale mocking (e.g., thousands of expectations)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Service Container: Register the Phiremock client as a singleton or context-bound service in Laravel’s IoC container for dependency injection.
      $this->app->singleton(PhiremockClient::class, function ($app) {
          return Factory::createDefault()
              ->createPhiremockClient(
                  new Host(config('phiremock.host')),
                  new Port(config('phiremock.port')),
                  Scheme::createHttps() // if secure
              );
      });
      
    • Testing Facades: Extend Laravel’s Http facade or create a custom facade (e.g., Phiremock) to abstract client interactions.
    • Artisan Commands: Build CLI tools to manage Phiremock state (e.g., php artisan phiremock:reset).
  • HTTP Clients:
    • Guzzle Integration: If using Guzzle v7, override the factory to avoid conflicts with Laravel’s guzzlehttp/guzzle dependency.
    • Symfony HTTP Client: Prefer Symfony’s client for Laravel 10+ projects to align with Symfony’s ecosystem.
  • Configuration:
    • Store Phiremock Server endpoints (host/port/scheme) in Laravel’s config/phiremock.php:
      return [
          'host' => env('PHIREMOCK_HOST', 'localhost'),
          'port' => env('PHIREMOCK_PORT', 8080),
          'scheme' => env('PHIREMOCK_SCHEME', 'http'),
          'secure' => env('PHIREMOCK_SECURE', false),
      ];
      

Migration Path

  1. Assessment Phase:
    • Audit existing mocking strategies (e.g., Http::fake(), VCR, or custom solutions).
    • Identify pain points (e.g., complex expectations, slow tests, or flaky mocks).
  2. Pilot Project:
    • Start with a single test suite (e.g., API feature tests) to evaluate the package’s fit.
    • Compare performance/memory usage against current tools.
  3. Incremental Adoption:
    • Phase 1: Replace simple mocks (e.g., Http::fake()) with Phiremock for reusable expectations.
    • Phase 2: Migrate scenario-based tests (e.g., OAuth flows) using Phiremock’s state management.
    • Phase 3: Adopt JSON Path for validating nested responses (e.g., GraphQL, CMS data).
  4. Tooling Integration:
    • Add Phiremock to Laravel’s test lifecycle (e.g., reset state before/after tests).
    • Example:
      // In TestCase setup/teardown
      public function setUp(): void
      {
          $this->phiremockClient->reset();
          parent::setUp();
      }
      

Compatibility

  • Laravel Versions:
    • Laravel 10+ (PHP 8.2+): Full compatibility with v2.0.0+ (recommended).
    • Laravel 9.x (PHP 8.1): Use v1.x (last release supporting PHP 8.1).
    • Laravel 8.x (PHP 7.4): Not supported; requires significant effort to backport.
  • PHP Extensions:
    • Ensure ext-json is enabled (required by the package).
    • For JSON Path, verify ext-json is up-to-date (bug fixes in PHP 8.2+).
  • Dependencies:
    • Guzzle v6/v7: Resolve conflicts by pinning versions or using the factory override.
    • PSR-18 Clients: Prefer Symfony’s HTTP client for Laravel 10+ to avoid duplication.

Sequencing

  1. Infrastructure Setup:
    • Deploy Phiremock Server (Docker recommended for consistency across environments).
    • Configure HTTPS if needed (e.g., self-signed certs for local dev).
  2. Laravel Integration:
    • Publish the package’s config to config/phiremock.php.
    • Register the client in AppServiceProvider.
  3. Testing Integration:
    • Replace Http::fake() with Phiremock for targeted test suites.
    • Update test helpers to use the new client (e.g., expectRequest()createExpectation()).
  4. CI/CD Pipeline:
    • Add Phiremock Server to CI environments (e.g., GitHub Actions, GitLab CI).
    • Example GitHub Actions step:
      - name: Start Phiremock Server
        run: docker-compose up -d phiremock
      - name: Run Tests
        run: php artisan test
      - name: Stop Phiremock Server
        run: docker-compose down
      
  5. Monitoring:
    • Log Phiremock interactions (e.g., failed expectations) to debug tests.
    • Example:
      $this->phiremockClient->listExecutions()->each(function ($execution) {
          if ($execution->isFailed()) {
              Log::error("Phiremock execution failed: " . $execution->getRequest()->getUri());
          }
      });
      

Operational Impact

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
sentix/ai-chatbot
codifyo/ts-generator-bundle
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