Problem/Motivation

Child issue of #1826054: [Meta] Expose Drupal Components outside of Drupal

Move tests in core/tests/Drupal/Tests/Components to their respective components under a tests/ directory.

Add test namespaces to 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.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#11 2943856_11.patch3.17 KBMile23
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Mile23 created an issue. See original summary.

Mile23’s picture

Immediately postponed on #2943842: Allow component namespaces to be autoloaded independently while we make sure the component namespaces work.

Mile23’s picture

Status: Active » Postponed
alexpott’s picture

One problem is that the regular runtime autoloader should not be able to autoload tests so each composer.json is going to need something like

    "autoload": {
        "exclude-from-classmap": [
            "/Tests/"
        ]
   },

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....

alexpott’s picture

Ah autoloading tests is not an issue! We can just add a testsuite like

        <testsuite name="Drupal Component Test Suite">
            <directory>./lib/Drupal/Component/*/Tests/</directory>
        </testsuite>

And use regular PHPUnit discovery!

alexpott’s picture

... because we should not have any other type of test than a unit test here :)

dawehner’s picture

While 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.

Mile23’s picture

@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.

Mile23’s picture

alexpott’s picture

@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.

Mile23’s picture

FileSize
3.17 KB

@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 TestDiscovery to 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:

$ ./vendor/bin/phpunit -c core --testsuite component --group Uuid

And you can also do this:

$ cd core/lib/Drupal/Component/Uuid/
$ ../../../../../vendor/bin/phpunit .

:-)

This patch also automatically adds the component testsuite to the unit testsuite, so whenever you say --testsuite unit you'll also run component. This is OK since all component tests must be unit tests, and they should fail anyway if they aren't.

$ ./vendor/bin/phpunit -c core/ --testsuite unit --group Uuid
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Testing 
.......

Time: 14.27 seconds, Memory: 66.00MB

OK (7 tests, 7 assertions)

Where this doesn't help us is run-tests.sh:

$ php ./core/scripts/run-tests.sh --types PHPUnit-Unit Uuid
  ERROR: Test group not found: Uuid

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.

alexpott’s picture

We 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.

Mile23’s picture

Having them run as part of Unit makes sense because it'll limit the need for changes to testbot.

Well, except that run-tests.sh doesn't use test suites. It's a completely different discovery system. So we still have to make TestDiscovery either 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. :-)