Problem/Motivation
Looks like ctools recently introduced some new tests which seem to have an undeclared dependency on views.
See e.g. https://www.drupal.org/pift-ci-job/1963329
PHP Fatal error: Class 'ViewsSqlTest' not found in /var/www/html/sites/all/modules/ctools/views_content/tests/src/views_content.test on line 11
The new tests were part of #3181701: 'More' link in Content pane display broken
Steps to reproduce
On a site with ctools but where views is completely absent (i.e. not on disk):
$ php scripts/run-tests.sh --list
Error: Class 'ViewsSqlTest' not found in include_once() (line 11 of /drupal-7.x/sites/all/modules/contrib/ctools/views_content/tests/src/views_content.test).
Proposed resolution
It actually looks like this is not truly an undeclared dependency, as the views_content submodule declares its dependency on views, as does the ViewsContentPanesTest class within its getInfo method.
However, simpletest seems to hit an exception when it tries to load the class to check its dependencies because the signature extends a class which may not exist.
There are probably a few different ways to avoid this - one is the pattern described here: https://stackoverflow.com/a/17325203
Remaining tasks
Work out how to fix this, do the patch dance etc..
User interface changes
n/a
API changes
n/a
Data model changes
n/a
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3196169-12_add_test_dependency.patch | 322 bytes | mcdruid |
| #12 | 3196169-12_early_return.patch | 473 bytes | mcdruid |
Comments
Comment #2
mcdruid commentedTIL: https://www.drupal.org/docs/7/creating-custom-modules/writing-module-inf...
Looks like you can add
test_dependencieswhich drupalci will pull in.So perhaps adding views as a test_dependency for the views_content submodule would fix this?
Hmm but views is already declared as a dependency there actually.
So is this more a problem with drupalci? I'll look into that some more.
Comment #3
mcdruid commentedI don't think this is specific to drupalci - I get the same thing locally if views is not available:
Comment #4
mcdruid commentedAFAICS simpletest tries to skip test classes which have unmet dependencies:
https://git.drupalcode.org/project/drupal/-/blob/7.78/modules/simpletest...
However, it looks like calling
class_exists()onViewsContentPanesTestcauses the exception as it extends a non-existent class... so itsgetInfomethod doesn't get a chance to declare its dependency on views - which looks like it would probably result in the class being skipped.So I think unless we're going to try and fix this in D7 core / simpletest, it'd be up to ctools to avoid this problem.
One option might be something like this: https://stackoverflow.com/a/17325203
...which seems a bit of a hack, but may avoid the problem outlined above?
Comment #5
mcdruid commentedThis seems to work AFAICS; it allows run-tests.sh / simpletest_test_get_all() to examine the class in order to decide (via getInfo) that it has unmet dependencies and should be skipped.
Comment #6
mcdruid commentedComment #7
mcdruid commentedComment #8
mcdruid commentedSome extra details about exactly how to reproduce this; you need to have ctools on disk but not views (which is the state drupalci creates when it's testing a module that depends on ctools but not views).
Example:
If views is there in the modules directory, the problem doesn't happen (I'm guessing this is down to autoloading).
Comment #9
megachrizI think that this fix is acceptable. I remember to have it seen in other modules in test classes.
Not in test classes, but a similar pattern to fix a problem like this:
https://git.drupalcode.org/project/date/-/blob/7.x-2.x/date.migrate.inc
https://git.drupalcode.org/project/rules/-/blob/7.x-2.x/includes/faces.inc
Comment #10
megachrizAn example in tests, added in #2876120: TUnit test dependency breaks simpletest UI:
https://git.drupalcode.org/project/feeds_ex/-/blob/7.x-1.x/src/Tests/Fee...
Comment #11
mcdruid commentedThanks for the examples @MegaChriz
Here's a patch with the simpler approach of just wrapping the whole class a check for the views class:
The extra indentation meant a comment needed to tweaked, but that's the only other change.
I prefer this to the middle-class hack.
Comment #12
mcdruid commentedDiscussed this in chat with @mixologic, @joelpittet and @MegaChriz.
There are (at least) two options:
class ViewsContentPanesTest extends ViewsSqlTest.There are a few different ways to do the workaround in the class file, but @joelpittet expressed a preference for the pattern used in date.migrate.inc in the example @MegaChriz provided in #9. It's quite minimal and avoids messing about with indentation.
@mixalogic confirmed that adding the test dependency will not work in a patch (we tried in #2796511-10: Custom headers); the change has to be committed to the .info file for drupalci to act upon it.
Here are patches for those two options; either ought to fix the problem. Steps to reproduce are in #8. It may be sufficient to clear caches between tests if you want to avoid a full reinstall every time.
N.B. testing manually won't confirm whether the test dependency fixes the problem, but you can simulate it by putting views into the modules directory.
It's up to the maintainers which approach they prefer.
Comment #13
mcdruid commentedAlso, for posterity, @mixologic confirmed that drupalci will not pick up dependencies from submodules (which are themselves a bit of a hack).
Comment #14
joelpittetI went with early return, I'd rather not add a test dependency for a submodule in the root module as I suspect that will have a performance issue and maybe others around including that while running tests.
Thanks for all your efforts on this!
Comment #17
joseph.olstadthis also came up in facetapi
#3230219: test bot failure
Comment #18
joseph.olstadhere's the commit that fixed this issue for facetapi:
https://git.drupalcode.org/project/facetapi/-/commit/11ab46f