Problem/Motivation
Child issue of #1826054: [Meta] Expose Drupal Components outside of Drupal
We want to be able to test Drupal's core Components in isolation as much as possible.
This enables testing the dependency bounds of the components themselves.
Proposed resolution
For each component:
File an issue to move the component tests.
Move tests in core/tests/Drupal/Tests/Components to their respective components under a Tests/ directory.
Add test directories to composer.json exclude-from-classmap.
Add test namespaces to composer.json require-dev.
The Transliteration component tests use data which is currently under src/data/. This should be moved to the tests/ directory, plus amend the tests that use this data.
Leave Drupal\Tests\Component\DrupalComponentTest where it is but modify it as needed.
Remaining tasks
Determine the fate of DrupalComponentTest.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2943856_11.patch | 3.17 KB | mile23 |
Comments
Comment #2
mile23Immediately postponed on #2943842: Allow component namespaces to be autoloaded independently while we make sure the component namespaces work.
Comment #3
mile23Comment #4
alexpottOne problem is that the regular runtime autoloader should not be able to autoload tests so each composer.json is going to need something like
And we need to handle this for core too... which is going to be fun because our test infra is rather bizarre in that it autoloads tests....
Comment #5
alexpottAh autoloading tests is not an issue! We can just add a testsuite like
And use regular PHPUnit discovery!
Comment #6
alexpott... because we should not have any other type of test than a unit test here :)
Comment #7
dawehnerWhile I understand that it is nice to have tests near the actual code I don't see the point of this being a child issue of #1826054: [Meta] Expose Drupal Components outside of Drupal. You would not use the tests anyway when you require these libraries.
Comment #8
mile23@dawehner: Currently, the requirements and version constraints in each of the components' composer.json file is at best a guess, because it's hard to test.
There's this issue which will never be fixed because the solution seems like its too complex to review: #2876669-40: Fix dependency version requirement declarations in components
That solution is complex because it has to create a whole other testing system just for the components. Having the tests local to the components would make it easier to understand what's going on in that sort of issue.
Comment #9
mile23We can't make this move until #2661542: Isolate Drupal\Tests\Component\Plugin\DefaultFactoryTest from core test module is in.
Comment #10
alexpott@Mile23 I'd argue that do to this right we should go component by component anyway. We're going to have to edit each component's composer.json, the testing docs, create a phpunit.xml.dist and get core to run the tests too.
Comment #11
mile23@alexpott: I'm not sure we need to do some of that. We'll definitely need to change TESTING.txt to whatever solution we arrive at.
We should also change
TestDiscoveryto use the test suites, and then also discover WTB tests.Here's a patch that adds a testsuite called 'component'. It's governed by
ComponentTestSuite.The patch moves the Uuid test to the component directory.
You can do this:
And you can also do this:
:-)
This patch also automatically adds the component testsuite to the unit testsuite, so whenever you say
--testsuite unityou'll also run component. This is OK since all component tests must be unit tests, and they should fail anyway if they aren't.Where this doesn't help us is run-tests.sh:
That's because run-tests.sh uses
TestDiscovery, which is above my pay grade to maintain at this point in time and space on this postponed issue.Comment #12
alexpottWe need to the do the component autoloader change. Tests classes here must not be autoloadable.
Having them run as part of Unit makes sense because it'll limit the need for changes to testbot.
Comment #13
mile23Well, except that run-tests.sh doesn't use test suites. It's a completely different discovery system. So we still have to make
TestDiscoveryeither pay attention to the test suite classes, or have it do its own version of discovering tests in the components.At this point I give a shoutout to #2863055-36: Move TestDiscovery out of simpletest module, minimize dependencies. :-)
Comment #14
mile23Contemplating #2849669-51: Fix \Drupal\Component\Utility\Unicode() because of the Symfony mbstring polyfill and this issue....
The problem is that if we move the tests to where the components are, we end up with tests in our source.
So the solution is something like this:
We could also split them out into individual directories, something like:
This would involve restructuring the subtree split, and changing some paths in composer merges. Also probably adding another test suite to phpunit called
components.Comment #15
alexpott@Mile23 we can also do exactly what Symfony does and use the
exclude-from-classmapkey likeI think this is the way to go.
Comment #16
mile23Ok, checking it out on the Uuid component.
$ cd core/lib/Drupal/Component/Uuid$ composer validate$ composer dumpautoload --no-devThe thing we verify here is that
Testsis excluded from the classmap, but we never declared a classmap, so it kind of doesn't matter in that regard. When we saycomposer dumpautoload -othe test file is excluded from the map, even if it's in the autoload-dev PSR-4 list.Comment #17
mile23Comment #19
mile23Maybe add a generic PHPUnit step to the testbot? #2837112-6: Add a test definition for a generic PHPUnit test run
It would give us drupalci.yml that would look like this:
...repeat for all the components.
Comment #21
MixologicRe-filing/re-tagging
Comment #24
mstrelan commentedI'd like to see the same for tests in
tests/Drupal/Tests/Composer. They currently depend on theDrupal\Composer\Composerclass which doesn't exist unless you checkout the git repo. This means you can't run the full core test suite from a site built from composer or tarballs. Moving the tests tocomposer/Testswould solve this.Comment #25
mile23We're still in technical debt mode on this because we don't have a way for run-tests.sh to run the tests outside of core/tests.
You can see how cumbersome it is now in #2876669: Fix dependency version requirement declarations in components, to the point that that issue is still outstanding.
Here's the travis CI version of it: https://github.com/paul-m/drupal_component_tester
I'm generally +1 on doing this for Composer stuff, in spirit. But it's also true that most of the Composer based tests are integration ones which build out a codebase from the git repo, to prove that it works. It might be that more strict unit tests could be moved to the composer/ directory, much as we'd do with components.