Skip to content

Writing Tests

Edit this page

Under the hood, Symfony UX Turbo relies on JavaScript to update the HTML page. To test if your website works properly, you will have to write UI tests.

Symfony Panther is a convenient testing tool using real browsers to test your Symfony application. It shares the same API as BrowserKit, the functional testing tool shipped with Symfony.

Install Symfony Panther and write a test for the task Turbo Frame:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// tests/TaskFrameTest.php
namespace App\Tests;

use Symfony\Component\Panther\PantherTestCase;

class TaskFrameTest extends PantherTestCase
{
    public function testEditTaskFrame(): void
    {
        $client = self::createPantherClient();
        $client->request('GET', '/task/1');

        $client->clickLink('Edit this task');
        $this->assertSelectorWillContain('turbo-frame#task_1', 'Save');
    }
}

Run bin/phpunit to execute the test. Symfony Panther automatically starts your application with a web server and tests it using Google Chrome or Firefox.

You can even watch changes happening in the browser by using: PANTHER_NO_HEADLESS=1 bin/phpunit --debug

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version