ModuleHandler::addModule() and ModuleHandler::addProfile() require that the module and path point to a valid module and if they are invalid weird things could happen. Sun said these should use the @internal annotations(#340723-185: Make modules and installation profiles only require .info.yml files) and these methods are for special cases like the installer. Even so, since they are public we should clarify. This clarification will also help regardless of accepting use of the @internal tag.

Comments

neclimdul’s picture

StatusFileSize
new1.04 KB
new690 bytes

Dope, copy and paste error.

sun’s picture

Component: documentation » extension system
StatusFileSize
new1.68 KB

Hm. I think we should rather throw an exception.

Status: Needs review » Needs work

The last submitted patch, 2: drupal8.modulehandler-add-exception.2.patch, failed testing.

neclimdul’s picture

StatusFileSize
new6.12 KB

yay! we found bugs!

I didn't fix any of the failures but here's a unit test of the functionality.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new8.3 KB
new9.46 KB

Hopefully we can agree on this one...

  1. Refactored test to not mock ModuleHandler itself.
  2. Added cache backend stub expectations.
  3. Fixed faulty DUTB tests.
sun’s picture

StatusFileSize
new8.11 KB
new842 bytes

Removed bogus preloaded module definition.

sun’s picture

StatusFileSize
new11.07 KB
new5.78 KB

Constructor-inject document root directory (defaulting to DRUPAL_ROOT) for test purposes.

sun’s picture

StatusFileSize
new10.12 KB
new4.69 KB

Supply DRUPAL_ROOT through a new getAppRoot() method instead. → Clean unit test override.

neclimdul’s picture

I prefer this approach.

Bogus preload is... truth is this test was pulled out of a larger patch to fix this specific issue. We could remove it but it provides a more realistic module handler for the error tests and its used in other tests I wrote so I'd prefer we keep it.

From discussion on IRC, my opinion:
Mocking module handler limits scope of the test to the code we're testing. Its not different than any of the mocks we build in our simpletest tests its just using the phpunit's mockBuilder to do it. resetImplementations() is a shared internal method so rather then test it on each public method that calls it, I chose to test that separately for clear units of testing and that's my design decision.

DRUPAL_ROOT is accepted global state and is expected to point to the root of the Drupal code base, lets not tackle that in this issue. I propose a follow up to discuss. This "pollutes" our tests with a global but one that is currently fundamental to Drupal, probably more so then the constant we're defining already in bootstrap.php.

neclimdul’s picture

um... my patch...

The last submitted patch, 5: modulehandler.add_.5.patch, failed testing.

sun’s picture

StatusFileSize
new10.12 KB

conflict.module--

sun’s picture

re: #9:

  1. The unit test will most likely need two separate ModuleHandler instances in the future — one with a constructor-injected list/set of extensions, and another one that is empty.

  2. While I can see the argument of testing a single method only, I disagree with mocking the class code under test through a dynamic mock code generator. That exceeds the level of sensible mocking in my book, because it's entirely not clear what the final state of the dynamically generated code is - unless you happen to know PHPUnit's internal code inside out.

    I doubt that anyone seriously understands those internals to fully understand the consequences. That's why I'm strongly opposed to the approach of mocking the class under test.

  3. The DRUPAL_ROOT problem space becomes a problem anyway, as soon as other ModuleHandler methods are being tested. The solution in #8 (by @msonnabaum) is finally one that makes sense to me (as a pattern + general approach for unit-testing classes that rely on DRUPAL_ROOT).

The last submitted patch, 6: modulehandler.add_.6.patch, failed testing.

neclimdul’s picture

1) Having written more tests on this class, maybe in the future but not for any of the ones I wrote. If that's the only thing blocking this issue I'll take it out though.
2) So first, the test works, you can muck up the implementation and see this. Second, we don't need to understand phpunit's code base and I don't feel like I should have to validate that its code works to use part of its API. I don't know every line of code making it work but the code is extensively tested not just in their tests but by being very widely used. That's why we're using phpunit.

For reference, the relevant documentation from the phpunit doubles section.
Below this example you'll see the documentation.
First bullet:

By default, all methods of the given class are replaced with a test double that just returns NULL...

Then lower the documentation for setMethods():

setMethods(array $methods) can be called on the Mock Builder object to specify the methods that are to be replaced with a configurable test double. The behavior of the other methods is not changed.

3) I stick by my argument with respect to this issue that this is a larger problem. Let me be a bit more clear, we should not make a special snowflake of this class. If we're going to fix this lets discuss it and fix it as a community not try to sneak something in an unrelated issue for this random class without a larger discussion. That may very well be the correct fix, lets not fix it _HERE_.

sun’s picture

Apologies, I was wrong here. Mocking the class under test in order to only test a specific unit (method) is indeed a possible testing practice. I have a better understanding of PHPUnit's internals now.

So unless this test has been committed as part of another issue already (IIRC, I've seen some similar code elsewhere?), let's move forward with your patch, @neclimdul. :)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

marvil07’s picture

Status: Needs review » Needs work

Indeed several hunks here are already inside core.

Moving to NW, since the patch does not apply anymore.

Also, based on last sun comment, I'm hiding not relevant patches.

marvil07’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

avpaderno’s picture

Version: 9.2.x-dev » 9.4.x-dev

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nicxvan’s picture

This can be closed one the related issue gets in.

nicxvan’s picture

It's in, I think we can close this, just not sure on credit.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

nicxvan’s picture

Status: Needs work » Closed (outdated)

The referenced methods have been removed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.