Problem/Motivation
This is a child issue of #3402007: Fix strict type errors in test modules. After fixing strict type issues we can add the strict_types declaration to all test modules.
Steps to reproduce
Add to phpcs.xml.dist:
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="spacesCountAroundEqualsSign" value="0" />
</properties>
<include-pattern>*/tests/modules/*</include-pattern>
<include-pattern>*/tests/*_test/*</include-pattern>
</rule>
Run phpcs:
composer phpcs
Proposed resolution
Run phpcbf:
composer phpcbf
Remaining tasks
Review individual commits of this MR to highlight the additional changes needed to make it pass.
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3400334
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:
- 3400334-declare-strict-test-modules
changes, plain diff MR !5309
Comments
Comment #3
mstrelan commentedComment #4
mstrelan commentedComment #5
mstrelan commentedComment #6
mstrelan commentedAlso postponed on #3439800: [pp-1] Standardize location of test modules
Comment #7
mstrelan commented#3439800: [pp-1] Standardize location of test modules is likely a won't fix, so we can continue with just the modules that match the patterns in the issue summary.
Comment #8
mstrelan commentedComment #9
mstrelan commentedWe can just about get away with combining this with #3400434: Enforce strict types in tests. I've updated the include/exclude paths as below:
I noticed the following additional files that I guess are technically out of scope for this issue, there may be a few others. Maybe we manually exclude them and address them in #3400434: Enforce strict types in tests?
core/modules/comment/src/Tests/CommentTestTrait.php
core/modules/contact/tests/drupal-7.contact.database.php
core/modules/system/tests/http.php
core/modules/system/tests/https.php
core/tests/bootstrap.php
Let's see what the testbot thinks anyway, there could be new errors introduced recently.
Comment #10
mstrelan commentedWell #9 was a bit ambitious. There are a few other traits and such that are problematic. Reverted to original scope. Looks like there are about 3 more tests to fix.
Comment #11
mstrelan commentedComment #12
smustgrave commentedLarge MR! I skimmed a few dozen files and does appear to just be added strict_type.
The deletions appear to be replacing few instances of space around the = sign.
Question for committers but seem it also added
/**
* @file
*/
To some test module files. Do we care if there is no description? Should a novice issue be opened to address those?
Comment #13
mstrelan commentedThanks for pointing out those @file things. Phpcbf seems to get confused adding strict types alongside @file blocks. I'll fix those up manually.
Comment #14
mstrelan commentedFixed all the @file blocks that were added when we already had them and rebased off HEAD.
Comment #15
smustgrave commentedTest failure appeared random
Latest updates still appear fine.
Comment #16
quietone commentedUnfortunately, this needs to be rebased.
I also noticed is that this is using the string
declare(strict_types=1);but, according to coding standards,there should be a space on each side of the "=" side. But later in the standard, the example for declaring string types uses the string as shown before. That is a problem for coding standards to sort out.I went through all the changes and did not find any problems with the changes.
Comment #17
mstrelan commentedWhere does it say to use a space? There was an issue and standards committee process for this and we settled on no space.
Comment #18
mstrelan commented#3303206: Define a standard for adding declare(strict_types=1)
Comment #19
mstrelan commentedComment #20
smustgrave commentedRebase seems good.
I actually remember in a few modules having the space and then randomly it went no space so had to fix a bunch myself.
Comment #21
quietone commentedSorry, my fault the standard for this does say that the space is omitted.
Comment #22
catchThis is still adding empty @file blocks which looks like a mistake? If it's not, the issue summary could use an update.
Comment #23
quietone commentedSorry about missing that. This should have corrected all the @file problems.
Comment #25
catchThanks looks good now. Getting this in while it still applies cleanly.
Committed/pushed to 11.x, thanks!