netresearch/typo3-testing-skill / skills/typo3-testing
typo3-testing
FlaggedUse when reproducing defects as failing tests, testing template or rendered output changes, confirming changes on a running TYPO3 instance, or setting up TYPO3 extension tests: unit/functional/E2E, PHPUnit 11-13, mutation testing, final-class mocks (v14), CI matrix across TYPO3 12/13/14.3 LTS, typo3-ci-workflows meta-package, CI failures. Also: transaction rollback, worker crashes, competing requests, testing-framework setup, test matrix, integration/e2e testing, coverage, test generation.
references/event-dispatch-testing.md
View on GitHub<!-- SPDX-License-Identifier: CC-BY-SA-4.0 -->
<!-- SPDX-FileCopyrightText: Netresearch DTT GmbH -->
# Event Dispatch Testing Patterns
## Testing Try/Catch Guarded Event Dispatch
When event dispatch is wrapped in try/catch for robustness, both the success and exception paths need testing.
### Pattern: Guarded Dispatch
```php
// Production code
try {
$event = $this->eventDispatcher->dispatch(
new ImageProcessedEvent($filePath, $result)
);
} catch (\Throwable $e) {
$this->logger->error('Event listener failed', ['exception' => $e]);
}
```
### Test: Success Path
```php
public function testEventIsDispatched(): void
{
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$eventDispatcher->expects(self::once())
->method('dispatch')
->with(self::isInstanceOf(ImageProcessedEvent::class))
->willReturnArgument(0); // PSR-14: dispatch() returns the (possibly modified) event
// ... invoke production code ...
}
```
### Test: Exception Path (Catch Block)
```php
public function testEventDispatchFailureIsLogged(): void
{
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$eventDispatcher->method('dispatch')
->willThrowException(new \RuntimeException('Listener failed'));
$logger = $this->createMock(LoggerInterface::class);
$logger->expects(self::once())
->method('error')
->with(
self::stringContains('Event listener failed'),
self::callback(function (array $context): bool {
return array_key_exists('exception', $context)
&& $context['exception'] instanceof \Throwable;
})
);
// ... invoke production code, verify it doesn't throw ...
}
```
## Testing PHP Warning/Error Functions
Functions like `getimagesize()` and `file_get_contents()` can trigger PHP warnings when given invalid input.
### Pattern: Suppressed Warning with Return Check
```php
// Production code
$size = @getimagesize($filePath);
if ($size === false) {
throw new InvalidImageException('Cannot read image dimensions');
}
```
### Test: Warning Trigger Path
```php
public function testInvalidImageThrowsException(): void
{
$this->expectException(InvalidImageException::class);
// Pass a non-image file to trigger the getimagesize failure
$processor->getImageDimensions('/path/to/not-an-image.txt');
}
```
### When to Use @ Suppression
| Context | @ OK? | Reason |
|---------|-------|--------|
| `@mkdir($dir, 0775, true)` | Yes | TOCTOU race condition — dir may be created between check and create |
| `@file_get_contents($path)` | Yes | If return value is checked (`=== false`) |
| `@getimagesize($path)` | Yes | If return value is checked (`=== false`) |
| `@unlink($path)` | Depends | OK in cleanup, not OK if deletion is critical |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |