Skip to content

[RFC] Move tests out of the source and source out of the tests #17749

Closed
@linaori

Description

@linaori

The Source

  • Often when I'm auto-completing classes in my IDE, I get the suggestion to use the *Test file.
  • Project wide searches and Usage Finder always shows tests using the search key or method/class etc.
  • KernelTestCase and WebTestCase are library dependencies in a test directory

I'm working on adding some functional tests to a bundle and this gave me a problem. I had to depend on the FrameworkBundle 2.3 for BC reasons but I couldn't depend on 2.3 because that one didn't have the KernelTestCase yet so I needed 2.5.

The Symptoms

For applications the recommended location is in /tests/. For Application bundles this seem to be /Tests/ and the same goes for re-usable bundles.

The current setup with the recommendations and implementations cause a few issues:

  • I need to load files from the vendor Tests in order to run my tests.
  • I get vendor test files which I can autoload and depend on.
  • 2 different recommendations for test locations.
  • I cannot easily exclude them from the distributed version.

The Solution

Personally I always put my code in bundles in the /src/ directory, this gives me a clean root directory and my tests in /test/. This leaves the root directory for all the meta-information for your package (example). So my suggestion is:

  • Extract the WebTestCase and KernelTestCase to another component (PhpunitBridge?) where they can reside in the source instead of test location.
  • Exclude the tests from the archive.
  • Not put the source in the package root but in /src/ like suggested for applications. Not going to happen due to subtree split.
  • Put tests in /test/ or /tests/ where they have an autoload-dev so they cannot be loaded in production code.

This will create a clearer structure where your source is not polluted by the tests and you cannot put anything of your public api in your tests (like the TestCases). When the test-cases are moved out, I can also require 2.3 or higher instead of 2.5 and higher (thus 2.7).

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions