{"id":20757,"date":"2018-08-16T14:06:13","date_gmt":"2018-08-16T14:06:13","guid":{"rendered":"https:\/\/blog.jetbrains.com\/phpstorm\/?p=13131"},"modified":"2024-01-09T14:51:34","modified_gmt":"2024-01-09T13:51:34","slug":"phpunit-composite-configuration-scope","status":"publish","type":"phpstorm","link":"https:\/\/blog.jetbrains.com\/pt-br\/phpstorm\/2018\/08\/phpunit-composite-configuration-scope","title":{"rendered":"PHPUnit composite configuration scope"},"content":{"rendered":"<p>PhpStorm 2018.2 comes with an extra level of flexibility for working with PHPUnit tests. Previously, you could run either a single method in a class, or all methods at once. Now, PhpStorm also lets you run an arbitrary selection of tests.<\/p>\n<p>To get started, right-click your test target, that is, a class or a method being tested, and invoke <em>Go To | Test<\/em> or press <em>Control+Shift+T<\/em> (<em>\u21e7\u2318T<\/em> for macOS).\u00a0Then,\u00a0select several tests to be executed\u00a0by\u00a0using\u00a0<em>Ctrl<\/em> (<em>\u2318<\/em> for macOS) and <em>Shift<\/em> keys.<\/p>\n<p>To\u00a0run your selection, use the provided keyboard shortcut (<em>Control+Shift+F10<\/em> for Windows and <em>\u2303\u21e7R<\/em> for macOS):<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13133\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-selecting_tests_to_run.png\" alt=\"selecting_tests_to_run\" width=\"457\" height=\"220\" \/><\/p>\n<p><!--more--><\/p>\n<p>As always, when a test session is over, PhpStorm will automatically create a temporary run\/debug configuration.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13135\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-run_debug_config_created-1.png\" alt=\"run_debug_config_created\" width=\"480\" height=\"55\" \/><\/p>\n<p>Let&#8217;s take a look at what&#8217;s inside. On the <em>Run\/Debug Configuration<\/em> screen, notice a new <em>Composite<\/em> option under <em>Test scope<\/em>. Having chosen it, we can make the test runner execute the tests based on the arbitrarily provided tests patterns, that is, classes, methods, or datasets:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13136\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-composite_run_debug_config_screen.png\" alt=\"composite_run_debug_config_screen\" width=\"800\" height=\"297\" \/><\/p>\n<p>The patterns that we&#8217;ve initially\u00a0run are already in place. To modify the selection, for example, to add some new test patterns to it, click <em>+<\/em>. Then, simply search for desired tests or locate them within your project files. PhpStorm is smart enough to detect the test patterns base directory path automatically based on your project structure. But if necessary, simply select the <em>Use alternative patterns base path<\/em> checkbox and provide the directory to search for test patterns in.<\/p>\n<p>If the chosen test method uses a data provider, you can refer to it in the <em>Data set<\/em> field. Note that in the case of several data sets, you need to create a separate pattern entry for each of them. Both numbered and named data sets are supported.<\/p>\n<p>To refer to a numbered data set, simply provide its index. You can freely omit the preceding number sign (<em>#<\/em>), in which case PhpStorm will insert it automatically in the resulting pattern:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-modifying_composite_configuration_thumbnail.png\" alt=\"Add a named data set\" width=\"682\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-modifying_composite_configuration.gif\" \/><\/p>\n<p>Similarly, to refer to a named data set, provide its name in the <em>Data set<\/em> field. There\u2019s no need to enclose the name in quotes: PhpStorm will add them automatically. If you do provide the quotes, though, the unnecessary extra ones will be trimmed. Moreover, if the data set\u2019s name itself contains quotes, they will be escaped properly:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-adding_named_datasets_thumbnail.png\" alt=\"Add a numbered data set\" width=\"690\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-adding_named_datasets.gif\" \/><\/p>\n<p>Speaking of data sets, composite test scopes will also save you a lot of time and effort when you need to rerun some failed data sets. Previously, your only option was to rerun either a single failed dataset, or the entire test.<\/p>\n<p>In PhpStorm 2018.2, you can simply click <em>Rerun failed tests<\/em> in the <em>Run<\/em> tool window: this will do the trick and only run the failed data sets:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-rerunning_datasets_thumbnail.png\" alt=\"Add a named data set\" width=\"790\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/08\/phpstorm-rerunning_datasets.gif\" \/><\/p>\n<p><em>Your JetBrains PhpStorm Team<\/em><br \/>\n<em>The Drive to Develop<\/em><\/p>\n","protected":false},"author":745,"featured_media":20758,"comment_status":"open","ping_status":"open","template":"","categories":[808,907],"tags":[602,743,91,359,443],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/20757"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/phpstorm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/745"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=20757"}],"version-history":[{"count":1,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/20757\/revisions"}],"predecessor-version":[{"id":431961,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/20757\/revisions\/431961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media\/20758"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=20757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=20757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=20757"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=20757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}