Problem/Motivation
This is a child issue of #3376057: [META] Add declare(strict_types=1) to all tests. After adding enabling strict types to all tests there were around 3000 errors. Fixing them all in one issue will lead to an enormous merge request that's difficult to review, as per the issue scope guidelines.
Steps to reproduce
See #3400334: Add declare(strict_types=1) to all test modules
Proposed resolution
- Fix all strict type issues in test modules in this issue
- Follow up #3400334: Add declare(strict_types=1) to all test modules
Remaining tasks
Review MR !5843
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3402007
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 #4
mstrelan commentedThanks for picking this up @marvil07
Can we change the approach from using rector to using phpcs/phpcbf? See #3400018: Add declare(strict_types=1) to all Functional JavaScript tests for example. We can include the rule in core/phpcs.xml.dist in this MR so we can make sure we've got everything.
I also found that for a lot of issues here we need to look at the HTML output to see an error message, as it the underlying error won't present itself in the test output.
Comment #5
marvil07 commented@mstrelan, thanks for the feedback.
I will try to take a look at the issue you mention for the next iteration, I did not see your comment until I was about to reply to the issue 😅.
Indeed, the plan is to identify the tests set with errors, then run them locally, and use the actual test error output URLs produced on the test run as needed, and fix the error.
I opened new MR #5790, intended to point to errors to fix.
As mentioned on its description, the plan is to rebase it to remove the first commit, so that can be done later at #3400334: Add declare(strict_types=1) to all test modules.
New commits on new `3402007-strict-types-test-modules-testonly` topic branch
- 4b73ae24c5 Declare strict types on test modules
- a5b8e85dbd Fix exception on RedirectOnExceptionTest
- 08643a6c68 Fix UncaughtExceptionTest
- 00def53870 No point in return after throwing an exception
The next step is to continue fixing the errors pointed by gitlab CI.
Comment #6
marvil07 commentedI have changed the approach to use phpcs configuration as the base for modifying the files in bulk.
That produced a few more changes.
I manually modified some of the files to move the
declare()after the@filedocblock, since it seems like in those cases phpcbf is adding an extra@filesection after adding thedeclare().I rebased the added changes on top.
And then, I continued with fixing errors as produced after the changes.
At this point four tests are missing to be fixed:
Drupal\FunctionalJavascriptTests\Core\CsrfTokenRaceTestDrupal\Tests\announcements_feed\FunctionalJavascript\AlertsJsonFeedTestDrupal\Tests\page_cache\Functional\PageCacheTestDrupal\Tests\system\FunctionalJavascript\Form\TriggeringElementTestChanges now on
3402007-strict-types-test-modules-testonlytopic branch- 7e02f7c188a Add phpcs rule for strict types on test modules
- f98517b9649 Require strict types across test modules
- f56a6768559 Fix exception on RedirectOnExceptionTest
- 6a34dd36f22 Fix UncaughtExceptionTest
- 3adb077ef52 No point in return after throwing an exception
- b06bc731952 Fix errors triggered from SessionTest
- 32688b5d85e Fix errors from FormTest
- 9ddfbea0ea7 Fix error thrown from SecurityAdvisoryTest
- b0eacbada1d Fix error thrown from RenderArrayNonHtmlSubscriberTest
- 5a9015ada2b Fix error thrown from AlertsJsonFeedTest
- 8982568c4e1 CS fix
- 959101d7958 A bit more error handling for WebDriverCurlService
- a175cb41347 One less nesting level on WebDriverCurlService added error handling
- 8266166b3d0 Get the curl error
- 57972a66c5f Fix error thrown from BlockFormInBlockTest
- 63d4287668a Fix errors thrown from EarlyRenderingControllerTest
Comment #7
mstrelan commentedComment #8
mstrelan commentedFixed
Drupal\Tests\page_cache\Functional\PageCacheTestComment #12
mstrelan commentedComment #13
smustgrave commentedLeft some comments where I could. Seems to cause a test failure though.
Comment #14
marvil07 commented@mstrelan, thanks for the extra test fixes!
@smustgrave, thanks for the extra review, I replied to your comments.
Line numbers
The error is related to line numbers.
One of the fixed tests needed a change of line numbers, because the new naturally declare() affects line numbers.
The new MR contains the changes without the declare() additions, since the task has been split in two steps.
In other words, we need to change line numbers in the test check when we are not adding the declare statements.
I have changed the rebased MR to match line numbers as needed.
using t()
As mentioned on the comment in the MR, we could change multiple tests to avoid using t(), but IMHO that is out of scope of this issue.
More details on my MR comment.
Next steps
Now that tests are passing again, and the threads on the MR has been replied to, I moving the issue back to NR.
Comment #15
smustgrave commentedBelieve feedback has been addressed. Agreed threads about t() are out of scope.
Comment #16
quietone commentedI'm triaging RTBC issues. I read the IS, the MR and the comments. I didn't find any unanswered questions.
I left comments in the MR, none of which affect the status of this issue. I did not do a thorough review of the MR.
Leaving at RTBC.
Comment #17
mstrelan commented@quietone you mentioned in #16 that you left comments in the MR, but I cannot see any comments from you there.
Comment #18
quietone commented@mstrelan, sorry about that. I have submitted them now.
Comment #19
larowlanLeft some comments, I think we should keep the intentionally broken code broken
Comment #20
mstrelan commentedI don't think the pattern we've used to find test modules is adequate. For example, jsonapi has plenty of modules with the pattern
tests/modules/json_test_*but we are just looking for*/tests/*_test/. Unfortunately not all test modules are found undertests/modules, for exampleaction_form_ajax_test, so we can't use that pattern either.Comment #21
mstrelan commentedOpened #3439800: [pp-1] Standardize location of test modules to address #20.
Comment #22
mstrelan commentedLet's just do the following patterns:
Anything outside of this can be caught later when we limit to
*/tests/*.Comment #23
quietone commentedUpdated the MR and made the changes for #22
Comment #24
smustgrave commentedThere one thread from @larowlan mentioning a followup so tagging for that. Rest appears to be addressed.
Comment #25
mstrelan commentedOpened followup issue #3461309: Refactor FormTestClickedButtonForm::buildForm
Comment #26
smustgrave commentedBelieve all feedback has been addressed
Comment #27
longwaveSuper nitpicky but it's cleaner just to declare the type than cast?
Comment #28
mstrelan commentedI agree with #27 that it would be cleaner, but we can't guarantee it's a string. See my comment on the MR for reasons why.
Comment #29
longwaveedit: deleted
Comment #30
mstrelan commentedIs that allowed with strict types? Thought it would say it expects a string and received a FormattableMarkup.
Comment #31
longwaveYeah, sorry, was wrong there, forgot this was all about strict types :)
Comment #32
longwaveIn which case as that was the only nit back to RTBC and I can commit.
Comment #37
longwaveBackported down to 10.3.x as test-only changes to keep things in sync.
Committed and pushed d43e2ba8f3 to 11.x and b3f2f8de04 to 11.0.x and 492839829a to 10.4.x and 50496b5e22 to 10.3.x. Thanks!