Problem/Motivation
While looking at #3567610: Adopt Core's stream wrapper, I realized that their could be some performance optimisation in the tests, for example in
tests/src/Kernel/PropTypeNormalization/BooleanPropTypeTest.php:
/**
* Provides data for testNormalization.
*/
public static function normalizationTests() : array {
return [
"null value" => [NULL, NULL],
"false value" => [FALSE, FALSE],
"true value" => [TRUE, TRUE],
"integer 0" => [0, FALSE],
"integer pos" => [22, TRUE],
"string empty" => ["", FALSE],
"string zero" => ["0", FALSE],
"string not zero" => ["22", TRUE],
"html" => ["<p>0</p>", TRUE],
"markup 0" => [["#markup" => "0"], FALSE],
"markup 1" => [["#markup" => "1"], TRUE],
];
}
Do not use data provider for kernel and functional tests. Data provider are nice for unit tests, but starting from kernel (and especially functional) tests, speed could be improved by not using it to avoid Drupal setup at each test case.
Proposed resolution
Add for each into the tests directly instead of using a data provider. Or call the data provider method in the tests and not as a "real" data provider.
Issue fork ui_patterns-3605477
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pdureau commentedComment #3
enomo103 commentedComment #5
enomo103 commentedComment #6
just_like_good_vibeslet's merge this proposition, we will discuss that later this morning
Comment #7
grimreaperHello,
Thanks for the MR and for providing KPIs about test execution time in the MR summary.
What is strange is that on the MR phpunit job: https://git.drupalcode.org/issue/ui_patterns-3605477/-/jobs/10523904
Compared with the latest pipeline of 2.0.x phpunit job: https://git.drupalcode.org/project/ui_patterns/-/jobs/10408958
I think it is normal that the number of tests is less because when using data providers each case is counted as an individual test. And also less PHPUnit deprecations which are triggered during setup I guess.
But I am surprised that there are less assertions and that the execution time is higher.
For the execution time, maybe it is due to CI?
PS: about assertions number, maybe it is due to the fact that there are assertions during the setup.
Comment #8
pdureau commentedThanks everybody. What about the functional tests?
Comment #9
grimreaperI searched for dataProvider in the codebase and it is used for unit and kernel tests.
So MR is ok.
Comment #11
mogtofu33 commentedAn other improvement could be to switch to parallel execution with Drupal runner.
But to do so we need to fix some tests namespace, group and coding standards.
In the meantime let's move to PHPUnit #attributes to be ready for the future!
As it's becoming big, moved to an other branch.
Comment #13
mogtofu33 commentedLooking good, with parallel tests we go from 9 minutes 56 seconds to 2 minutes 18 seconds!
The phpstan issue is on deprecated code, what's our moto for that?
Comment #14
grimreaperComment #16
grimreaperThe deprecation detected by PHPStan in
modules/ui_patterns_field_formatters/tests/src/Kernel/Source/FieldFormatterSourceTest.phpmade me think, I was expecting to see atests/src/Kernel/Source/FieldFormatterSourceTest.phpbut that's not the case.Putting a comment to not forget, when deprecating modules/ui_patterns_field_formatters/src/Plugin/UiPatterns/Source/FieldFormatterSource.php, as the test been moved to the main module too.
I finish for this work session, need to check.
Comment #17
grimreaperDiscussed with @pdureau, effectively from commit https://git.drupalcode.org/project/ui_patterns/-/commit/f4fb6a8e27da0a17... the tests:
- modules/ui_patterns_field_formatters/tests/src/Kernel/Source/FieldFormatterSourceTest.php
- modules/ui_patterns_field_formatters/tests/src/Kernel/Source/FieldLabelSourceTest.php
had not been moved to the main module.
I will do that.
Comment #19
grimreaper