Run tests with code coverage
PhpStorm provides a dedicated action for running tests with the code coverage measurement.
Run tests with coverage using an existing configuration
To run tests with coverage using a previously created run configuration, do one of the following:
Press Alt+Shift+F10 to open the Cover.
popup, select the required configuration, click to the right of it, and then selectFrom the toolbar, select the required run configuration from the configurations list, click to expand its options and select
.
Run tests with coverage from the Project view
To run a test or multiple tests with coverage from the Project view, do the following:
Right-click a specific test file or a directory containing the required tests.
From the context menu, select the corresponding run command, for example,
.
Run tests with coverage from the editor
Click Run in the gutter next to the required test class or method and from the context menu that opens, select .
If the Show options before applying coverage to the editor checkbox has been selected in Settings Ctrl+Alt+S Coverage, a dialog appears where you can choose whether you want to replace the active coverage suites, add the collected data to the active suites, or not apply coverage data. You can also opt to skip this dialog in the future. In case any other option has been selected, the respective action will be performed silently.
Now you can explore the collected coverage data in the Coverage tool window, the Project tool window, and in the editor.
Manage coverage suites
The collection of coverage data for a specific run is called a coverage suite.
PhpStorm can display the results for one or more coverage suites at once. If multiple suites are selected, the IDE displays merged results from these suites. This means that a line is considered covered if it was executed in at least one of the selected suites.
The corresponding suite files are located in the PhpStorm's system directory:
%LOCALAPPDATA%\JetBrains\PhpStorm2024.3\coverage
~/.cache/JetBrains/PhpStorm2024.3/coverage
~/Library/Caches/JetBrains/PhpStorm2024.3/coverage
Manage suites
In the main menu, go to
Ctrl+Alt+F6.In the Choose Coverage Suite to Display menu:
Use the checkboxes to select active suites. Active suites define the coverage data that is currently displayed in the IDE.
Use Add to import external suite file, for example, generated in the CI server or sent to you by someone else.
To view an imported suite collected with PhpStorm runner, you do not have to compile or run the project.
Use Remove to remove a suite from the list but keep the file in the storage.
Use Delete to remove a suite from the list and delete the file from the storage.