Skip to content

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.

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.

srcTests/UserServiceTest.php
<?php
declare(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.

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:

Terminal window
php srcTests/run.php

The exit code is 0 when all tests pass and 1 otherwise.

  • run.php discovers *Test.php files in the directory and runs every public test* method, printing ok or FAIL per test plus a pass/fail summary.
  • Support/TestCase.php is a base class with assertSame, assertTrue, assertFalse, assertNull, and assertThrows. Assertion failures throw AssertionFailed.
  • Support/StubPropertySource.php is an in-memory PropertySource for tests. Choose the dataset via the dataset key of the propertySources entry in the fixture yml, and register rows in StubPropertySource::$datasets before building the context.
  • fixtures/<name>/application.yml is a config directory you pass to new WinterPropertyContext(['.../fixtures/<name>']).
  1. Create the test file

    Create SomethingTest.php in srcTests/, namespace winterBootTests, class SomethingTest extends \winterBootTests\Support\TestCase.

  2. Add public test methods

    Add public methods starting with test. No registration is needed; run.php picks the file up automatically.