Add PHPUnit setup and run tests in CI - #3
Merged
Merged
Conversation
The package shipped no automated tests, and CI only ran composer validate and php -l. These packages are published to Packagist and installed independently, so a regression here reaches every install with nothing catching it. Adopts the scaffolding package-template already carries and the modules never received: orchestra/testbench in require-dev, autoload-dev for the test namespace, phpunit.xml, a testbench TestCase registering the module's service provider, and a `Run tests` step in the workflow. .gitignore keeps vendor/ and the phpunit cache out of the repo. PackageIntegrityTest covers the wiring that fails silently rather than loudly, none of which needs a database or the host app: - the declared service providers exist and actually boot, so a renamed provider cannot quietly stop Laravel auto-discovery - module.json parses, carries the fields PackageSeeder reads, and its package_name matches the composer package, so the module cannot register in add_ons under a key nothing can enable - every class under src/ sits at the path its PSR-4 prefix implies - migration filenames are unique and well formed, so one cannot silently never run, and each file returns a real Migration PSR-4 is checked by reading the declared namespace rather than by autoloading: module classes extend host app classes that do not exist outside an install, so loading them would fatal on the parent instead of reporting the mapping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of zerp-pk/zerp#48, which tracks every published module shipping zero automated tests and no CI to run them.
CI here existed but only ran
composer validateandphp -l. Nothing executed a test, because there were none.What's added
The scaffolding
package-templatealready carries and the modules never received:orchestra/testbenchinrequire-dev,autoload-devfor the test namespace,scripts.test"php": "^8.2"inrequire, which was previously an empty objectphpunit.xmland a testbenchTestCaseregistering the module's service providerRun testsstep in the workflow, andtestsadded to the lint path.gitignore, sovendor/and the phpunit cache stay out of the repoWhat the tests actually check
PackageIntegrityTesttargets the wiring that fails silently rather than loudly. None of it needs a database or the host app, so it runs on a bare checkout in CI:module.jsonparses and has the fieldsPackageSeederreadsadd_onsrowsmodule.jsonpackage_namematches the composer packageadd_onsunder a key nothing can enablesrc/sits at its PSR-4 pathloadMigrationsFrom()keys by filename, so a duplicate means one migration never runsMigrationPSR-4 is verified by reading each file's declared namespace rather than by autoloading it. Module classes extend host app classes (
App\Http\Controllers\Controller,App\Models\User,App\Models\Concerns\TenantScoped) that do not exist outside an install, soclass_exists()would fatal on the missing parent instead of reporting the mapping. Worth noting as its own problem: these packages have hard, undeclared dependencies on host app classes.Verification
Run locally against all 32 module packages before opening these PRs. All 32 green, ~1,600 assertions total.
composer validate --strictis clean on all 32.