Problem/Motivation
Docs in CronInterface say:
* Do not call this function from a test. Use $this->cronRun() instead.
First, this is incomplete -- what is $this representing here? There is no cronRun() method on the interface.
It what is meant is \Drupal\Tests\Traits\Core\CronRunTrait -- that's the only place in core I can find a function with this name. The full name should be given in the docs.
Second, this is partially incorrect, or possibly predates the existence of Kernel tests, because the code of cronRun() is this:
$this->drupalGet('cron/' . \Drupal::state()->get('system.cron_key'));
Unit and Kernel tests can't do browser requests with drupalGet().
So the docs are misleading, and should say that the function should be used in *browser* tests.
Third, I'm not clear why cron should be run by making a browser request, rather than through the API. That should be explained too.
Steps to reproduce
Proposed resolution
Update the PHPDoc for CronInterface::run()
to remove misleading guidance and improve clarity:
- Removed the inaccurate reference to
$this->cronRun()
, which is not part of the interface and may confuse developers. - Replaced it with a detailed and accurate summary of what the method does.
- Added guidance recommending not to call this method from PHPUnit tests, suggesting proper alternatives for test coverage.
Remaining tasks
- Determine if last change was correct (Adding full stop (.) to end of comment lines)
- Review