Testing Winter Boot Applications with #[WinterBootTest]
Winter Boot ships a #[WinterBootTest] stereotype that registers a class as a first-class bean during startup, plus a small zero-dependency test runner (srcTests/run.php) that the framework itself uses. Together they let you write integration tests that exercise your services against a real DI container without pulling in PHPUnit.
The #[WinterBootTest] attribute
Section titled “The #[WinterBootTest] attribute”Apply #[WinterBootTest] to any class. The container treats it the same way it treats #[Service] or #[Component]: it registers the class as a bean, resolves its dependencies via #[Autowired], and runs its #[PostConstruct] hooks.
<?phpdeclare(strict_types=1);
namespace com\example\test;
use dev\winterframework\stereotype\Autowired;use dev\winterframework\stereotype\test\WinterBootTest;
#[WinterBootTest]class UserServiceTest{ #[Autowired] private UserService $users;
public function testCreateUser(): void { $id = $this->users->create('alice', 'alice@example.com'); // assert on $id }}The attribute lives at dev\winterframework\stereotype\test\WinterBootTest.
The bundled test runner
Section titled “The bundled test runner”Winter Boot’s own tests use a plain PHP runner with no external dependencies. You can lift the same pattern into your project.
From the repository root:
php srcTests/run.phpThe exit code is 0 when all tests pass and 1 otherwise.
Layout
Section titled “Layout”run.phpdiscovers*Test.phpfiles in the directory and runs every publictest*method, printingokorFAILper test plus a pass/fail summary.Support/TestCase.phpis a base class withassertSame,assertTrue,assertFalse,assertNull, andassertThrows. Assertion failures throwAssertionFailed.Support/StubPropertySource.phpis an in-memoryPropertySourcefor tests. Choose the dataset via thedatasetkey of thepropertySourcesentry in the fixture yml, and register rows inStubPropertySource::$datasetsbefore building the context.fixtures/<name>/application.ymlis a config directory you pass tonew WinterPropertyContext(['.../fixtures/<name>']).
Add a test
Section titled “Add a test”-
Create the test file
Create
SomethingTest.phpinsrcTests/, namespacewinterBootTests, classSomethingTest extends \winterBootTests\Support\TestCase. -
Add public test methods
Add public methods starting with
test. No registration is needed;run.phppicks the file up automatically.
Related pages
Section titled “Related pages”- Dependency injection explains how the container resolves
#[Autowired]dependencies in test beans. - Application lifecycle covers container boot order that also applies to test contexts.