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 Tests Laravel Package

http-interop/http-factory-tests

PHPUnit test suite to verify PSR-17 HTTP factory implementations. Configure phpunit.xml with constants pointing to your Request/Response/ServerRequest/Stream/UploadedFile/Uri factory classes, then run the included integration tests from vendor.

View on GitHub
Deep Wiki
Context7

Getting Started

Add this package as a dev dependency to your project:

composer require --dev http-interop/http-factory-tests

Then, create a test class that extends one of the provided base test suites (e.g., HttpFactoryTestCase) and implement the abstract createFactory(): FactoryInterface method to return your PSR-17 factory implementation. Run tests with phpunit. This immediately validates compliance for ServerRequestFactoryInterface, ResponseFactoryInterface, StreamFactoryInterface, and UriFactoryInterface.

Note for PHP 8 / PHPUnit 9 users: Version 0.7.0 now supports PHP 8 and PHPUnit 9, so ensure your phpunit.xml or phpunit CLI version aligns accordingly. If upgrading from earlier versions, verify that your test environment does not conflict with PHP 8+ type hints or scalar return types (e.g., string in getUri() return declarations).

Implementation Patterns

  • Integrate into CI: Include these tests in your automated test suite to catch regressions early—especially when upgrading PSR-7/PSR-17 implementations or PHP versions.
  • Factory inheritance: Extend from HttpFactoryTestCase in your tests/ directory and override createFactory() to test multiple factory implementations (e.g., Nyholm/psr7, Laminas/Diactoros, Symfony/HttpFoundation adapters).
  • Custom edge-case layers: Add your own test methods beyond the provided suite to cover project-specific behavior (e.g., custom header normalization or URI encoding rules), while still leveraging the base tests for PSR compliance.
  • Multi-implementation validation: In monorepos or framework integrations, use one shared test class across packages to guarantee consistent factory behavior in client/server contexts (e.g., testing Guzzle’s PSR-17 bridge alongside Laminas Http client).
  • Leverage PHP 8 compatibility: You can now safely use PHP 8 attributes (e.g., #[Used], readonly classes) in your test implementations without interference from the test suite.

Gotchas and Tips

  • Version lock: Prior to 0.7.0, this package had outdated runtime compatibility (last updated 2020). With 0.7.0+, PHP 8 and PHPUnit 9 are officially supported—but verify psr/http-factory v1.0.x is used; newer PSR-7/PSR-17 clarifications (e.g., withUploadedFiles() immutability) may still require manual validation.
  • Missing factory expectations: The suite tests creation only—verify mutator behavior (e.g., withHeader(), withStatus()) with your own tests, as PSR-7 factories don’t define mutator validation.
  • Autoloading: If tests fail with “Class not found” errors, ensure phpunit.xml includes your tests/ dir in <php><includePath> or use a proper bootstrap—especially important if using PHP 8’s class autoloading stricter rules.
  • Override selectively: You may override specific test methods (e.g., testCreateUploadedFile() for special multipart handling) to relax or tighten expectations without duplicating the whole suite.
  • Complement with other tools: Pair with php-http/discovery tests and nyholm/psr7-factory-bench to catch edge-case deviations across environment-specific factories (e.g., Apache vs. CLI SAPI).
  • Deprecation of older PHPUnit versions: PHPUnit <9.5 is no longer supported in 0.7.0; update your CI config (PHPUNIT_VERSION=9.6 or higher) to avoid fatal errors from removed APIs (e.g., PHPUnit\Framework\TestCase::getMock()).
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport