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

Http Factory Implementation Laravel Package

psr-mock/http-factory-implementation

Lightweight PSR-17/PSR-7 HTTP factory/message mock implementation for PHP 8.1+. Built for SDKs and libraries to test against PSR interfaces without hard deps, with strict PSR compliance and helpful debugging API.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • PSR Compliance: Continues to align with PSR-17 (HTTP Factory) and PSR-7 (HTTP Message) standards, maintaining Laravel’s compatibility. No architectural changes impact this fit.
  • Testability Focus: Retains its strength in isolating HTTP-dependent logic for unit/integration testing, particularly valuable for Laravel’s middleware, controllers, and HTTP clients.
  • Isolation: Lightweight design remains unchanged, preserving minimal coupling with production code.

Integration Feasibility

  • Laravel Ecosystem: Still seamlessly integrates with Laravel’s PSR-7/17 implementations (e.g., symfony/http-foundation or nyholm/psr7), though PHP 8.1+ is now required.
  • Dependency Injection: Compatible with Laravel’s service container for mocking HTTP factories, but PHP 8.1+ is now mandatory, which may require updates to CI/CD pipelines or legacy environments.
  • Mocking Complexity: Simplifies testing of HTTP logic without full HTTP server setups, but PHP 8.1+ dependency may limit adoption in older Laravel projects (e.g., Laravel 8.x or earlier).

Technical Risk

  • PHP Version Requirement: Breaking change—projects using PHP <8.1 (e.g., Laravel 8.x or older) will need upgrades. Mitigate by auditing PHP versions and planning migrations.
  • Limited Adoption: Still low stars/release activity; stability remains unproven. Test thoroughly in staging.
  • PSR Versioning: Ensure compatibility with Laravel’s PSR-7/17 implementations (e.g., Symfony HTTP Foundation v6.x+). No changes here, but PHP 8.1+ may indirectly affect this if Laravel’s dependencies enforce stricter PSR versions.
  • Edge Cases: Verify handling of non-standard HTTP features (e.g., cookies, custom headers) in Laravel’s context—no updates to the package address this.

Key Questions

  1. PHP Version Support: Does your Laravel project (or CI/CD) support PHP 8.1+? If not, what’s the migration path?
  2. Laravel Version Support: Does the package explicitly support Laravel’s PSR-7/17 implementations (e.g., Symfony HTTP Foundation v6.x+) under PHP 8.1+?
  3. Mock Granularity: Can it still mock specific HTTP factory methods (e.g., createRequest(), createResponse()) without side effects in PHP 8.1+?
  4. Performance Overhead: Does PHP 8.1+ introduce measurable runtime differences in test suites?
  5. Alternatives: How does this compare to Laravel’s built-in HttpTestCase or Mockery for PHP 8.1+ projects?
  6. Future-Proofing: Will the package evolve with PHP 8.2+ or PSR updates (e.g., PSR-33)? The changelog doesn’t indicate plans, but PHP 8.1+ is now a hard requirement.

Integration Approach

Stack Fit

  • Primary Use Case: Unit/integration tests for:
    • Controllers/middleware interacting with HTTP clients (PHP 8.1+ required).
    • Custom HTTP factories or request/response transformations.
    • Legacy code relying on PSR-7 messages (if upgraded to PHP 8.1+).
  • Secondary Use Case: Mocking external APIs in feature tests (e.g., webhook handlers) only in PHP 8.1+ environments.

Migration Path

  1. PHP Version Upgrade (if <8.1):
    • Update PHP to 8.1+ in local/dev/staging environments.
    • Update CI/CD pipelines (e.g., GitHub Actions, Docker) to use PHP 8.1+.
    • Test Laravel compatibility (e.g., Laravel 9.x+ recommended).
  2. Dependency Addition:
    composer require --dev psr-mock/http-factory-implementation:^1.0
    
  3. Test Setup:
    • Replace existing HTTP mocks with the package’s factory (same as before, but now PHP 8.1+ required).
    • Example:
      use PsrMock\HttpFactory\MockHttpFactory;
      $factory = new MockHttpFactory(); // Requires PHP 8.1+
      $request = $factory->createRequest('GET', '/test');
      
  4. Laravel Integration:
    • Bind the mock factory to the container in tests (unchanged):
      $this->app->instance(\Psr\Http\Message\RequestFactoryInterface::class, $factory);
      

Compatibility

  • PSR-7/17: Directly compatible with Laravel’s PSR-7 messages and PSR-17 factories under PHP 8.1+.
  • HTTP Clients: Works with Laravel’s Http facade or custom clients (e.g., Guzzle) only if PHP 8.1+ is supported.
  • Middleware: Mockable for testing middleware but limited to PHP 8.1+ environments.

Sequencing

  1. Phase 0 (if needed): Upgrade PHP to 8.1+ and test Laravel compatibility.
  2. Phase 1: Replace simple HTTP mocks in unit tests (e.g., Mockery or hardcoded responses).
  3. Phase 2: Extend to integration tests for HTTP-dependent logic (e.g., API clients).
  4. Phase 3: Evaluate for feature tests (e.g., webhook validation) if performance is acceptable in PHP 8.1+.

Operational Impact

Maintenance

  • PHP Dependency: Critical update required—PHP <8.1 projects cannot use this package. Plan for:
    • PHP version upgrades.
    • Dependency updates (e.g., Laravel 9.x+).
    • CI/CD pipeline changes.
  • Low Effort: MIT license and lightweight design still reduce maintenance burden post-upgrade.
  • Dependency Updates: Monitor for PSR-7/17 breaking changes (e.g., Symfony HTTP Foundation updates) in PHP 8.1+.

Support

  • Limited Community: Lack of stars may still require internal documentation or issue tracking.
  • Debugging: Mocks may obscure real HTTP behavior; ensure test assertions are explicit regardless of PHP version.
  • Alternatives: Fallback to Mockery or Laravel’s HttpTestCase if PHP upgrades are blocked or issues arise.

Scaling

  • Test Suite Growth: Scales well for large test suites in PHP 8.1+ environments.
  • Performance: Minimal overhead in tests; no impact on production.
  • Parallel Testing: Compatible with Laravel’s pest or phpunit parallelization if PHP 8.1+ is used.

Failure Modes

  • PHP Version Blockers: Projects stuck on PHP <8.1 cannot adopt this package. Critical risk for legacy systems.
  • Mock Leaks: Accidental use of mocks in production (mitigate via test-only bindings).
  • PSR Incompatibility: Breaking changes in Laravel’s PSR-7/17 implementations under PHP 8.1+.
  • Test Fragility: Overly complex mocks may require frequent updates post-upgrade.

Ramp-Up

  • Learning Curve: Minimal for PHP/Laravel developers familiar with PSR standards and PHP 8.1+.
  • Documentation: Internal docs may still be needed due to lack of external resources.
  • Onboarding: Pair with existing test examples to demonstrate usage (e.g., mocking a GET /api request) after PHP upgrade.
  • Training: May require upskilling teams on PHP 8.1+ features (e.g., named arguments, union types) if migrating from older versions.
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