Tip
Use the table of contents in the left panel to navigate.
Running the Tests
The extension ships two test suites, compatible with TYPO3 13.4 and 14:
|
Suite |
Location |
What it covers |
|---|---|---|
|
Unit |
|
Manager, channels, traits, models, queue handler. No TYPO3 instance. |
|
Functional |
|
A real TYPO3 instance: DI wiring, email delivery, database storage, queue handler, repositories, custom channels registered by another extension, and every public way of sending a notification. |
The functional tests load a fixture extension
(Tests/). It plays the
role of a third-party integrator: it registers custom channels and captures
sent emails in memory, so no mail is ever sent. By default they use
SQLite, so no database server is needed.
Without DDEV
Requires PHP 8.2+ (with pdo_) and Composer, run from the extension
directory:
composer install
# Unit tests
.Build/bin/phpunit -c Build/phpunit-unit.xml
# or: composer test:php:unit
# Functional tests
.Build/bin/phpunit -c Build/phpunit-functional.xml
# or: composer test:php:functional
Warning
Composer cannot install the dependencies on an exFAT volume (plugin installation fails). Use an APFS/ext4 disk, or DDEV.
With DDEV
The extension directory contains a DDEV configuration:
ddev start
ddev composer install
# Unit tests
ddev exec .Build/bin/phpunit -c Build/phpunit-unit.xml
# Functional tests on SQLite
ddev exec .Build/bin/phpunit -c Build/phpunit-functional.xml
# Functional tests on the DDEV MySQL server
ddev exec typo3DatabaseDriver=mysqli typo3DatabaseHost=db \
typo3DatabaseUsername=root typo3DatabasePassword=root typo3DatabaseName=func_test \
.Build/bin/phpunit -c Build/phpunit-functional.xml
The functional tests create one database per test class (prefixed with
typo3Database), so the database user needs CREATE DATABASE
privileges. That's why the example uses root.
Useful Options
# Run a single test class or method
.Build/bin/phpunit -c Build/phpunit-functional.xml --filter PublicApiTest
.Build/bin/phpunit -c Build/phpunit-unit.xml --filter sendNowBypassesTheMessageBus
# Show deprecations (useful when preparing the next TYPO3 major)
.Build/bin/phpunit -c Build/phpunit-functional.xml --display-deprecations
# Test against a specific TYPO3 version
composer update -W --with "typo3/cms-core:^13.4"
composer update -W --with "typo3/cms-core:^14.3"
Any other database can be used through the typo3Database,
typo3Database, typo3Database, typo3Database,
typo3Database and typo3Database environment variables.
Testing Your Own Notifications
The fixture extension is also a working example of how to test code that sends notifications:
Classes/— a mail transport that keeps sent emails in memory. Enable it in a functional test withMail/ Capturing Transport. php $GLOBALS(or['TYPO3_ CONF_ VARS'] ['MAIL'] ['transport'] = Capturing Transport:: class $configuration), then assert onTo Use In Test Instance Capturing.Transport::$messages Classes/— a custom channel that records what it receives, registered withChannel/ Attribute Tagged Channel. php #.[Autoconfigure Tag] Configuration/— registersServices. yaml Yamlwith an explicitTagged Channel notifications.tag.channel
In unit tests, mock Notification and register it with
General to assert that notify /
notify are called, without delivering anything:
$dispatcher = $this->createMock(NotificationDispatcherInterface::class);
$dispatcher->expects(self::once())->method('send')->with($user, $notification);
GeneralUtility::addInstance(NotificationDispatcherInterface::class, $dispatcher);
$user->notify($notification);