Problem/Motivation
Poking around to evaluate #2803247: Incorrect namespace for CacheExampleForm I found that its test implements \Drupal\simpletest\WebTestBase, which is currently being deprecated in core: #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)
Also, the cache test is named CacheExampleTestCase, which should end in Test instead of TestCache.
Proposed resolution
- Make sure that all tests subclass
Drupal\Tests\BrowserTestBase. - Tests should be moved into [module]/tests/src/Functional and out of src/Tests
- Make sure test classes end in *Test so PHPUnit autoloads them.
- Make that test functions start with test* so PHPUnit will run them.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | interdiff.txt | 9.23 KB | mile23 |
| #29 | 2821387_29.patch | 72.11 KB | mile23 |
| #22 | interdiff.txt | 7.6 KB | mile23 |
| #22 | 2821387_22.patch | 71.33 KB | mile23 |
| #20 | interdiff.txt | 8.28 KB | mile23 |
Comments
Comment #2
rfayUpdated issue summary.
Comment #3
rfayComment #4
mile23Comment #5
rfayI'm at file_example, and maybe I'll get the rest done on the plane this afternoon. We can hope.
Comment #6
rfayHere is the conversion to phpunit for the remaining modules.
Comment #8
rfayComment #11
rfayFrom https://dispatcher.drupalci.org/job/default/242568/console
It looks like the FieldExample one is a test system failure??? or a failure in simpletest module?
The pager_example one is an assert on a link that works fine locally, but that probably is difference in the testing system somehow. I run nginx, it's running apache, etc.
Comment #12
mile23OK, so if you can't fix them here, leave those out of the patch and we can make extra issues for those modules.
Comment #13
rfayYou're so smart. This removes field_example and pager_example, which have been split out into separate patches.
Comment #15
rfayComment #16
mile23Working on a re-roll.
Comment #17
mile23Reroll.
Also:
Comment #18
mile23PHPCS says:
More review-y:
Wait... How is this going backwards from BTB to simpletest?
Needs to go to cron_example/tests/src/
Bunch of whitespace errors. This or #2799535: Convert SimpleTestExampleController to use DescriptionTemplateTrait will need a re-roll anyway.
Not especially happy with this in our test. Could the path controller need new caching directives?
Comment #19
mile23Needs a re-roll after #2799535: Convert SimpleTestExampleController to use DescriptionTemplateTrait
Comment #20
mile23Reroll plus fixed all the CS errors.
Still to do: Review stuff from #18.
Comment #22
mile23Dealt with all the stuff in #18 and more. Notable exception is #18.4 which needs a follow-up.
Poking through, I found a few modules that didn't have a conversion.
The notable exception being dealt with here: #2821773: Convert field_example tests to phpunit functional
Holy cow
phpunit_examplestill has::getInfo()! :-)Comment #23
Torenware commentedTest fails if they're removed?
Comment #24
mile23I haven't investigated. That'd be the follow-up. :-)
Comment #25
mile23The tests fail if we remove
drupal_flush_all_caches()so I filed #2843199: Figure out why TableSortExampleTest needs drupal_flush_all_caches() in the test as a follow-up, since this issue is about doing the conversion.Comment #26
rfaySomebody sorted that for us at the time, as I remember: #2821742: Tablesort Example nonfunctional for non-admin user
Comment #27
Torenware commentedThis is near finished. In general, the right way to do a port is to change as little as you can get away with. This port is mostly done the right way.
The one thing that personally I would change: I think it's important that asserts immediately tell you what went wrong if and when they fire. Mostly, you get this by using the correct assertion function. The more specific the assertion you use, the more informative it is.
The main problem in the current patch is where you don't have a good specific assertion, and need to do things like check the count of some object or record. In these cases, the assertion used is typically ::assertEquals(N, count(Something)). In these cases, I think that adding custom assertion text is best practice, since the error is not that "the numbers are not equal" -- the problem is that there is some number of Something != N.
YMMV, but since tests are intended to help developers track down problems in their code, "literate assertions" are a good practice.
Besides this, I don't see anything that needs changing before this is committed.
General point about omitting the "info" part of an assert: if the assert goes off, is it obvious what went wrong. In this case, the usage with the Simpletest assertion is better than the Mink assert, since "not 2" does not tell you what went wrong, as the original did.
Same as above; it won't be clear what "not 1" means.
Several more examples of asserts that will have cryptic messages if they are triggered.
A few more examples of asserts that won't explain themselves.
Comment #28
Torenware commentedAgain, near done. Assertions just need to be a little more informative in some corner cases.
Comment #29
mile23Hope this documents adequately.
Changed some assertion types while I was at it.
Comment #31
Torenware commentedGentlemen -- you are proud fathers of an... issue.
Committed.
Comment #32
Torenware commentedComment #33
mile23Bit of a follow-up: #2843692: Drupal\Tests\cron_example\Functional\CronExampleTest is failing