![]() ![]() If you need to have a nullable type in the test method, I recommend splitting it into two separate methods and data providers. When using data providers, it means adding parameter type hints to the method that accepts data sets and adding a return type (and phpdoc) to data provider method: [ I always add type hints to the method definitions when possible. When I want to run a single data set from the PhpStorm I usually just comment out all the other data sets. When you have the JetBrains issue tracker open, please also vote for WI-43811 (possibility to go to the data set from the test results). ![]() PhpStorm does not currently allow you to run a single data set from the code (please vote for the issue WI-43933), but you can run all of them and then rerun one from the test results. -filter runs named data sets that match the regexpĭon't forget to check the other possible patterns in docs.-filter space and newline are trimmed" runs specific named data set.-filter "testTrimTrims#0-2" runs data sets #0, #1 and #2.-filter "testTrimTrims#2" runs data set #2 (third data set, as the array keys start at zero). ![]() Here are examples of what is possible (the documentation shows examples with ', but that does not work on Windows, where you have to use " to wrap the argument): You can do so by using PHPUnit's -filter option in CLI. When there is something wrong with one of the data sets, you probably want to run the test only with it. Tip #2: You can run single data set from data provider I recommend that you name the data sets the same way you would use for separate tests. It makes test results much easier to understand: 'trailing space and newline are trimmed' => [ Let's say you are implementing your own trim function and you need to test it with lots of tests like the following one: [ This is useful when you are writing some text filtering, transformations, URL generation, price calculations, etc. I think that even if you are already using Data Providers, you will find some of those tips useful.ĭata Providers are a handy feature of PHPUnit which allows you to run the same test with different inputs and expected results. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |