Developer Experience (DX) refers to how smooth and efficient it feels to work with a framework or tool. In Symfony 7.4, we've added many small DX improvements, and this post highlights some of them.
Preparing the Session in Functional Tests
Symfony provides many utilities to work with the session in your web applications.
In Symfony 7.4, we added new utilities to make it easier to work with sessions in
functional tests. The $client used in tests now includes a getSession()
method that returns the session so you can store data in it.
For example, you can use this to preset CSRF tokens, A/B testing data, user preferences, or any other stateful information required for your tests:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// tests/Controller/FormControllerTest.php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FormControllerTest extends WebTestCase
{
public function testSetupCsrfTokenBeforeFormSubmit(): void
{
$client = self::createClient();
$session = $client->getSession();
$session->set('_csrf/form', 'fhr8d5sha3a69tpv24s5');
$session->save();
$client->request('POST', '/form', ['form' => ['_token' => 'fhr8d5sha3a69tpv24s5']]);
}
}
Improved Route Debugging
The debug:router command is an essential tool for inspecting and debugging
routing issues in your applications. In Symfony 7.4, we've improved it in several ways:
- The
SchemeandHostcolumns are only displayed when their values differ fromANY, making the output cleaner and easier to read; - The
Methodcolumn now displays HTTP methods in color, using the same color conventions as other common tools such as Swagger (blue forGET, yellow forPOSTandPUT, etc.).
Before:
After:
Better Form Accessibility
In Symfony 7.4, when errors occur in Symfony forms, the fields with validation
errors now include the correct aria-invalid and aria-describedby
attributes according to WCAG 2.1 (specifically, the ARIA 21 technique).
No changes are required in your forms. Just upgrade to Symfony 7.4, and your application will automatically become more accessible to your users.
Mocking the PHP strtotime() Function
The Clock component provides the Symfony\Bridge\PhpUnit\ClockMock class,
which allows you to mock PHP's built-in time functions: time(), microtime(),
sleep(), usleep(), gmdate(), and hrtime().
In Symfony 7.4, we've added the strtotime() function to this list, so you can
now mock it in your tests as well.
More Precision When Consuming Messages
The messenger:consume command is the central piece when consuming messages
routed by the Messenger component. The --all option is a convenient
shortcut to consume messages from all receivers. In Symfony 7.4, this command
has been improved with a new option called --exclude-receivers.
This new option is used together with --all to exclude specific receivers
(e.g. failed receivers) when consuming messages:
1 2 3
$ php bin/console messenger:consume --all \
--exclude-receivers=queues1 \
--exclude-receivers=queues2
Automatic Integration of FrankenPHP Worker Mode
FrankenPHP is a modern, high-performance PHP application server created by long-time Symfony contributor Kévin Dunglas. Recently, the FrankenPHP project moved under the PHP organization (see github.com/php/frankenphp), becoming the official application server for PHP applications.
FrankenPHP offers multiple execution modes. One of them is worker mode, which boots your application once and keeps it in memory to achieve massive performance gains.
Symfony 7.4 improves the integration with FrankenPHP worker mode. You no
longer need to install the runtime/frankenphp-symfony package. Just upgrade
to Symfony 7.4, which natively supports FrankenPHP worker mode out of the box.
FrankenPHP worker mode, native support: amazing!
Is that true? I see no dependency on Clock component in the PHPUnit Bridge, it has it's own mocking system that has nothing to do with Clock component