Currently it doesn't seem like there's any way of running kernel tests in a multisite setup, where a module is within a site's directory.
Where a module exists at drupal_root/sites/sitename/modules/custom/my_module, it doesn't seem possible to run PHPUnit kernel tests for any tests within that module. (I'd assume functional tests too, but I can't get those working on my machine right now :D)
The problem comes right at the start during setup:
public static $modules = ['my_module'];
It seems that this is because Simpletest installs itself in a new site directory, eg drupal_root/sites/simpletest/, it doesn't have access to the modules in the other directory. As far as I can tell the only directories it scans are drupal_root/core, drupal_root/sites/all, drupal_root and drupal_root/sites/simpletest/###
This was while running the tests directly, eg $ phpunit drupal_root/sites/sitename/modules/custom/my_module/tests/src/NameOfTest.php, so it wasn't an automated discovery/testsuite issue.
If there is a way of running PHPUnit tests within a multisite installation then it doesn't seem to be documented anywhere. This seems like a pretty major omission.
Would it be possible for example to pass in a "site" paramater to the PHPUnit command, so that it runs within a particular site directory? Or allow discovery of modules from other directories?
Comments
Comment #2
joachim commented> Would it be possible for example to pass in a "site" paramater to the PHPUnit command, so that it runs within a particular site directory?
Given that the test class knows it's testing this module in sites/sitename/modules/custom/my_module, this should be something the test class code can specify.
That way the developer doesn't have to worry about it when running tests from the command line, and is saved the repetition.
Though:
> Or allow discovery of modules from other directories?
This seems like the better option to me. I happened to poke around at at \Drupal::service('extension.list.module') this morning, and that is aware of modules in all site directories.
Comment #3
cilefen commentedThis reminds me a little of another issue.
Comment #4
sophie.sk@cilefen - yes, I spent today trying to get that patch installed, only to realise we actually already had that patch on the site, so it clearly hasn't helped :( I thought it might be related, though.
@joachim - I'm not sure which would be more useful. Discovery of modules would be good for groups (eg
$ phpunit --group=my_modules_that_span_across_different_sites), but mimicking a Drupal install by passing in a site parameter would also be handy (becausesite_onedoesn't and shouldn't have access to the modules insite_two).Why not do both then?! Open source devs don't have enough to do already :D
Comment #9
super_romeo commentedComment #10
super_romeo commentedWorkaround:
Comment #12
tunprog@super_romeo Thank you but it didn't work for me.
I changed the location of the module temporarily just to finish writing tests then I will get back to this later.
Comment #16
kevinquillen commentedAs a workaround, for Kernel tests, you can do this:
for Functional tests:
this worked for me to get my tests moving.