Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Autoload tests dir using autoload-dev #105

Open
cobbles opened this issue Oct 26, 2024 · 1 comment
Open

Feature Request: Autoload tests dir using autoload-dev #105

cobbles opened this issue Oct 26, 2024 · 1 comment

Comments

@cobbles
Copy link

cobbles commented Oct 26, 2024

Heya 👋 Thanks for your hard working maintaining this package 😄

Context

The default behavior for creating a new module is to include the tests directory in the autoload of the modules composer.json file.

    "autoload": {
        "psr-4": {
            "Modules\\Order\\": "src/",
            "Modules\\Order\\Tests\\": "tests/",
            "Modules\\Order\\Database\\Factories\\": "database/factories/",
            "Modules\\Order\\Database\\Seeders\\": "database/seeders/"
        }
    },

This makes it easy to run run tests as they get autoloaded as part of the modules package.

The Problem

Including the the tests dir as part of the autoload and not putting it in autoload-dev means that we cant make use of

composer dumpautoload --dev

and

composer dumpautoload --no-dev

Which is valuable when building a production image in order to keep tests out of production code as well as keeping the overall size (Mb) of the final built image as lean as possible.

Possible Solution

Since composer wont let you autoload the dev dependencies of packages in the vendor dir (or modules in our our case) we could instead do two things

  1. Split out the autoloading in the modules composer.json to follow the normal conventions

modules/order/composer.json

    "autoload": {
        "psr-4": {
            "Modules\\Order\\": "src/",
            "Modules\\Order\\Database\\Factories\\": "database/factories/",
            "Modules\\Order\\Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Modules\\Order\\Tests\\": "tests/"
        }
    },
  1. In the root composer.json file we add the tests dir to the autoload-dev section as well

composer.json

    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/",
            "Modules\\Order\\Tests\\": "modules/order/tests/"
        }
    },

This would allow us to still easily run tests after creating a new module but also allow us to exclude test files from production build images.

Lemme know your thoughts and if its something your keen to implement I would be happy to submit a PR

@cobbles cobbles changed the title Feature Request: Autoload tests as a using autoload-dev Feature Request: Autoload tests dir using autoload-dev Oct 26, 2024
@cobbles
Copy link
Author

cobbles commented Nov 13, 2024

Heya just touching base on this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant