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

Cyril Vmd
Contributed by Cyril Vmd in #61110

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

Maximilian Pesch
Contributed by Maximilian Pesch in #59780

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 Scheme and Host columns are only displayed when their values differ from ANY, making the output cleaner and easier to read;
  • The Method column now displays HTTP methods in color, using the same color conventions as other common tools such as Swagger (blue for GET, yellow for POST and PUT, etc.).

Before:

Debug Router output before Symfony 7.4

After:

Updated debug Router output after Symfony 7.4

Better Form Accessibility

Jean-François Morin-Abdullah
Contributed by Jean-François Morin-Abdullah in #60902

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

Jean-Philippe Rivet
Contributed by Jean-Philippe Rivet in #60424

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

Jean-Baptiste Delhommeau
Contributed by Jean-Baptiste Delhommeau in #60979

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

Alexandre Daubois
Contributed by Alexandre Daubois in #60503

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.

Published in #Living on the edge