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

Test Support Laravel Package

yiisoft/test-support

Testing utilities for Yii applications: helpers and fixtures to simplify unit and integration tests, isolate dependencies, and improve readability. Provides common test tools you can reuse across packages and projects.

View on GitHub
Deep Wiki
Context7

Getting Started

This package provides foundational utilities for testing Yiisoft-based applications, particularly for integration and unit tests. Start by installing it via Composer:

composer require --dev yiisoft/test-support

The primary entry point is the Yiisoft\Test\Support\Container\ContainerTraverser and Yiisoft\Test\Support\TestCase\TestCase, which you’ll extend in your test classes. Begin by replacing your base test class with Yiisoft\Test\Support\TestCase\TestCase, which sets up a clean application container and handles reset between tests.

Implementation Patterns

  • Container reset between tests: Extend TestCase to get automatic container isolation. Use setUp() and tearDown() as usual—TestCase handles resetting the container state.
  • Test trait reuse: Leverage traits like ContainerTrait to inject container-aware functionality into non-TestCase classes (e.g., test helpers or custom fixtures).
  • Stubs and mocks: Use Yiisoft\Test\Support\Stub namespace classes (Stub\ClassWithDependencies, Stub\NullLogTarget, etc.) for predictable test doubles without relying on external frameworks.
  • Integration testing setup: For HTTP integration tests, combine with yiisoft/yii-web-testtest-support provides the low-level container tools that web-test builds on.

Gotchas and Tips

  • Container state leaks: Even with TestCase, manually instantiated containers outside the test case lifecycle won’t auto-reset—always use $this->container provided by the test case.
  • Static caches: PHP static properties won’t reset between tests. Use ContainerInterface::clear() or stub dependencies that cache state.
  • Version skew: This package is tightly coupled to Yiisoft core versions. Ensure yiisoft/test-support matches your yiisoft/core and yiisoft/di versions.
  • Missing PHPDoc annotations: Some stubs lack strict types—use them only for testing, not production expectations.
  • Extensibility: Override createContainer() in your test case for custom container configurations (e.g., pre-loading config overrides or test-only providers).
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
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
twbs/bootstrap4