Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For more unit testing fun.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2456877-module-invoke-wrapping-1.patch | 1.5 KB | e0ipso |
Comments
Comment #1
e0ipsoAdded patch.
Comment #2
e0ipsoComment #3
donquixote CreditAttribution: donquixote commentedHi e0ipso,
the
MockDrupalSystem::moduleInvoke()
is not needed in the regular DrupalSystem.What would we gain by adding it?
Comment #4
donquixote CreditAttribution: donquixote commentedComment #5
e0ipsoThis will help other modules to use the
DrupalSystem
to unit test their code. In particular I needed this for a module that callsmodule_invoke_all
in a method that I want to unit test.Comment #6
donquixote CreditAttribution: donquixote commentedAh. This sounds fun!
Tbh, so far I wrote this as "good enough for xautoload". I don't know how well it will perform for other modules. I guess it would be "use at your own risk".
Maybe if we are serious about this, it should become a dedicated library on github. Then we could add it with the composer.json with require-dev.
What is your experience so far? Do you think it already is in a decent shape, or does it need a lot of changes to be universally useful? Do you think it is fine to continue maintaining this as part of xautoload, or does this impose too many limitations?
We could leave it as part of xautoload for a while, add minor improvements like the one you suggest, and then some day in the future it could still go to github.. It just means we need to change the (unwritten) goal for this thing.
Comment #7
donquixote CreditAttribution: donquixote commentedAlso, if other modules start using this, we need to start worrying about API stability.
So far I can do refactoring like renaming methods and changing their behavior, without having to worry about 3rd party code.
Comment #8
e0ipso@donquixote I had a satisfactory experience with it, although I changed course at some point. I am using now the Service Container module to inject dependencies instead of XAutoload's DIC. While I was using XAutoload I was pleased with it and it worked well (after copying the unit tests in xautoload into my own module).
Regardless of that, I think it would be really beneficial to have an object oriented Drupal 7 wrapper library. That would allow module implementors to use it to inject the services they need to call any D7 core function.
Comment #9
donquixote CreditAttribution: donquixote commentedDo you use the service container module in combination with the DrupalSystem from xautoload?
Or do you have something custom now?
I don't think you need the xautoload service container to use the mock classes in your own project..
Btw, maybe you are interested in this one: https://github.com/donquixote/d8plugin
And you should enable issues in https://github.com/mateu-aguilo-bosch/plug. Currently it seems that only PRs are enabled, but issues are not.
Comment #10
donquixote CreditAttribution: donquixote commentedYes!
I just imagine it to be a lot of work until it is universally useful.
And there should be a consistent conversion pattern. Maybe, as a rule, 1 function = 1 class? And 1 procedural file = 1 namespace?
Not every of those needs an interface. Only those parts that are going to be used in a specific module.
If a Drupal module wants to use the interfaces from this library, e.g. DrupalSystemInterface, then it will need something like composer manager to have this stuff downloaded.
Maybe there could be two libraries: One with just the interfaces and real implementations (direct call to the Drupal procedural function), and another library with mock implementations.
Or a module could have something like DrupalSystemInterface and DrupalSystem built-in, taylored to its own use. And then a MockDrupalSystem that is defined in the module, but that uses the components provided by the library.
The goal would be to only have the dependency for testing with phpunit.