/symfony-hexagonal:symfony-testingfrom symfony-hexagonal
Provides testing patterns for Symfony hexagonal architecture with PHPUnit 10-13, PHPStan 2, and Foundry 2 factories. Covers test directory structure mirroring src/, pure domain unit tests, handler tests with in-memory adapters, functional API tests, and TDD workflow.
Ships in symfony-hexagonal. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in testing within Symfony hexagonal architecture.
| Topic | Rule | Versions |
|---|---|---|
| Test methods | test_ prefix or #[Test] attribute; never @test / @dataProvider doc-comments | annotations removed in PHPUnit 12 |
| Data providers | #[DataProvider('name')] + public static function name(): iterable | PHPUnit 10+ |
| Stubs vs mocks | createStub() for return values, createMock() only with expects() | PHPUnit 13 emits notices for mocks without expectations |
| Assertions | self::assert*() (static) | all |
| PHPUnit per PHP | 11 → PHP 8.2, 12 → PHP 8.3, 13 → PHP 8.4 | pick from the detected PHP version |
| PHPStan | 2.x, level 8 minimum (9-10 recommended for new code) | checkGenericClassInNonGenericObjectType removed in 2.0 |
| Foundry | 2.x: PersistentObjectFactory / ObjectFactory, defaults(), class() | ModelFactory was Foundry 1 |
tests/
├── Unit/
│ └── Domain/
│ └── {Module}/
│ ├── Entity/
│ │ └── {Entity}Test.php
│ └── ValueObject/
│ └── {ValueObject}Test.php
├── Integration/
│ └── Application/
│ └── {Module}/
│ ├── Command/
│ │ └── {Handler}Test.php
│ └── Query/
│ └── {Handler}Test.php
├── Functional/
│ └── Presentation/
│ └── {Module}/
│ └── API/
│ └── {Controller}Test.php
└── Support/
├── Adapter/
│ ├── InMemory{Entity}Repository.php
│ ├── SequentialIdGenerator.php
│ └── FakePasswordHasher.php
└── Factory/
└── {Entity}Factory.php
namespace Tests\Unit\Domain\User\ValueObject;
use App\Domain\User\Exception\InvalidEmailException;
use App\Domain\User\ValueObject\Email;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class EmailTest extends TestCase
{
public function test_valid_email_is_created(): void
{
$email = new Email('[email protected]');
self::assertSame('[email protected]', $email->value);
}
#[DataProvider('invalidEmails')]
public function test_invalid_email_throws_exception(string $invalid): void
{
$this->expectException(InvalidEmailException::class);
new Email($invalid);
}
/** @return iterable<string, array{string}> */
public static function invalidEmails(): iterable
{
yield 'no at sign' => ['invalid'];
yield 'empty' => [''];
yield 'no domain' => ['user@'];
}
public function test_emails_are_equal(): void
{
self::assertTrue((new Email('[email protected]'))->equals(new Email('[email protected]')));
}
}
namespace Tests\Integration\Application\User\Command;
use App\Application\User\Command\RegisterUser;
use App\Application\User\Command\RegisterUserHandler;
use App\Domain\User\ValueObject\UserId;
use PHPUnit\Framework\TestCase;
use Tests\Support\Adapter\FakePasswordHasher;
use Tests\Support\Adapter\InMemoryUserRepository;
use Tests\Support\Adapter\SequentialIdGenerator;
final class RegisterUserHandlerTest extends TestCase
{
public function test_it_registers_a_user(): void
{
$users = new InMemoryUserRepository();
$handler = new RegisterUserHandler($users, new FakePasswordHasher(), new SequentialIdGenerator());
$id = $handler(new RegisterUser('[email protected]', 'Test', 'password123'));
self::assertNotNull($users->findById(new UserId($id)));
}
}
Prefer in-memory fakes over mocks for ports: tests then assert on state, not on call sequences, and survive refactoring.
namespace Tests\Functional\Presentation\User\API;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
final class UserControllerTest extends WebTestCase
{
public function test_create_user(): void
{
$client = static::createClient();
$client->loginUser(/* a SecurityUser with ROLE_USER_CREATE */);
$client->jsonRequest('POST', '/api/users', [
'email' => '[email protected]',
'name' => 'Test User',
'password' => 'Password123',
]);
self::assertResponseStatusCodeSame(201);
$response = json_decode((string) $client->getResponse()->getContent(), true, flags: JSON_THROW_ON_ERROR);
self::assertNotNull($response['result']['id']);
self::assertNull($response['error']);
}
}
$client->jsonRequest() and $client->loginUser() work on every supported version. loginUser() authenticates through the test session, so it fits session-based firewalls; for a stateless token firewall, send a real token header (e.g. HTTP_AUTHORIZATION) instead.
See references/ for detailed guides:
test-organization.md - phpunit.xml.dist (PHPUnit 10-13), suites, PHPStan, CI, Foundry 2test-patterns.md - In-memory adapters, builders, Messenger transport assertions, functional patternsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
symfony-testing, phpunit, phpstan, hexagonal-architecture, tdd, foundry
npx claudepluginhub aligundogdu/symfony-hexagonal-skill --plugin symfony-hexagonal10 skills in this plugin
/symfony-api-responseSymfony REST API response standard {result, error, extra, status}: thin controllers, #[MapRequestPayload] / #[MapQueryString] request DTOs, ApiResponseTrait, exception subscriber that unwraps Messenger HandlerFailedException, validation error format, debug mode. Use when: API, endpoint, controller, response, error handling, JSON, REST, API response, exception subscriber, HTTP, request DTO/symfony-cqrs-handlersSymfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp/symfony-doctrine-persistenceDoctrine persistence for Symfony hexagonal architecture (ORM 2.x/3.x, DBAL 3/4, DoctrineBundle 2/3): repository adapters, XML mapping in Infrastructure, embeddables, enums, custom DBAL types, native lazy objects, migrations, transactions, read models with DBAL QueryBuilder, strict no-native-SQL rule. Use when: doctrine, repository, persistence, database, mapping, migration, ORM, entity manager, DBAL, transaction, query builder, pagination/symfony-domain-modelingSymfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status/symfony-hexagonal-architectureSymfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade/symfony-messenger-asyncSymfony Messenger async processing and Symfony Scheduler instead of cron: transports, routing (#[AsMessage] 7.2+), retry with backoff and jitter, failure transport, idempotency keys, DeduplicateStamp (7.3+), workers, supervisor, scheduled commands with stateful/locked schedules. Use when: messenger, async, queue, retry, scheduler, background job, worker, transport, message queue, cron, scheduled task, idempotency, deduplicationOther plugins' skills for the same job