fix: export-ignore tests/ and namespace global Document mock (#129)#53
Open
kojiromike wants to merge 2 commits into
Open
fix: export-ignore tests/ and namespace global Document mock (#129)#53kojiromike wants to merge 2 commits into
kojiromike wants to merge 2 commits into
Conversation
Add .gitattributes export-ignore for tests/ and dev-only paths so neither the GitHub source tarball nor `composer archive` ships them. Move the global-namespace MockDocument into the module's Tests\Mocks namespace and class_alias it to \Document in tests/bootstrap.php. The phpstan.neon ignore-list gains a `class Document` entry for standalone analysis. This is the cookiecutter template new modules are generated from, so the fix propagates to every future generated module. Mirrors the precedent established in openCoreEMR/oce-module-sinch-fax#146. Refs openCoreEMR/oce-module-junction-labs#129 Assisted-by: Claude Code
Round out the .gitattributes export-ignore set with dev/agent files that were missed in the initial pass: .composer-require-checker.json, .dclintrc.yaml, .yamlfmt, CLAUDE.md, bin/setup, and bin/precommit-template-guard.sh. All are referenced only from CI hooks, the template's one-time setup wizard, or local agent guidance — never from runtime module code. src/Command/SetupCommand.php is deliberately left shipping: per the spec, src/ ships whole, and that file is meant to be removed by bin/setup during the template's first-run customization, not pruned out of the archive. Refs openCoreEMR/oce-module-junction-labs#129 Assisted-by: Claude Code
There was a problem hiding this comment.
Pull request overview
This PR updates the module template to prevent test-only artifacts (especially mocks) from leaking into consumer OpenEMR trees via distribution archives, and avoids collisions with OpenEMR’s global \Document class during static analysis.
Changes:
- Adds
.gitattributesexport-ignorerules to excludetests/and other dev-only files fromgit archive/composer archive. - Moves the
Documenttest mock out of the global namespace into a module test namespace, and aliases it back to\Documentat runtime intests/bootstrap.php. - Adds a PHPStan ignore rule related to the global
Documentclass during standalone analysis.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/Mocks/MockDocument.php |
Namespaces the Document mock and updates return types for mock getters. |
tests/bootstrap.php |
Adds class_alias() to map the namespaced mock to global \Document at test runtime. |
phpstan.neon |
Adds an ignore rule for PHPStan messages involving Document during standalone analysis. |
.gitattributes |
Introduces export-ignore rules to keep dev/test files out of archives distributed to consumers. |
Comments suppressed due to low confidence (1)
tests/Mocks/MockDocument.php:104
get_data()is declared as?string, but the?? ''fallback makes it impossible to returnnull(and will also treat an explicitly-setnullas empty string). If callers rely onnullvs empty-string to distinguish “missing” content, this mock can’t currently simulate that.
public function get_data(): ?string
{
if (isset($this->data['throw_exception']) && $this->data['throw_exception']) {
throw new \Exception($this->data['exception_message'] ?? 'Document error');
}
return $this->data['data'] ?? '';
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
This is the cookiecutter template new OpenEMR modules are generated from, so this fix propagates to every future generated module.
Part 1 —
.gitattributesexport-ignore (general fix):Excludes
tests/and dev-only paths (.github/,Dockerfile.test,compose.yml,Taskfile.yml,phpunit.xml,phpcs.xml,phpstan.neon,rector.php,.pre-commit-config.yaml,.editorconfig,cleanup.sql,DEVELOPMENT.md,GETTING_STARTED.md, release-please configs) fromgit archiveandcomposer archive. Runtime paths (src/,templates/,public/,openemr.bootstrap.php,table.sql,version.php,info.txt,composer.json,LICENSE,README.md) keep shipping. Author/dev-time tooling —bin/setup,bin/precommit-template-guard.sh,tools/, and.composer-require-checker.json— is also export-ignored: authors clone the git repo (export-ignore doesn't affect clones), and the runtime CLI consumers actually invoke isbin/install-module.php, which is not ignored and still ships.Part 2 —
class_aliasthe global Document mock:tests/Mocks/MockDocument.phpdeclaredclass Documentin the global namespace. When the module dist is installed into anopenemr-internalconsumer tree, whole-tree static analyzers (PHPStan, Rector) parsed this as a second definition of the real\Document, corrupting type inference.The mock now lives at
OpenCoreEMR\Modules\{ModuleName}\Tests\Mocks\MockDocument, with?stringreturn types mirroring the real\Document's untyped getters over nullable properties.tests/bootstrap.phpclass_alias()es it to\Documentso code under test that doesnew \Document(...)still resolves.phpstan.neongains an ignore for the globalclass Documentfor standalone analysis.Why
Mocks under
tests/were leaking into consumer trees via the dist archive. Part 1 is the generalizing fix (consumers never parse any mock). Part 2 specifically resolves the proven-bad globalDocumentcollision in line with the sinch-fax precedent.Precedent
Mirrors openCoreEMR/oce-module-sinch-fax#146 exactly.
Tracking issue
Refs openCoreEMR/oce-module-junction-labs#129
Test plan
git archive HEAD | tar -tf -excludestests/,.github/, and dev-only files; preservessrc/,public/,templates/,composer.json,LICENSE,README.md,info.txt,openemr.bootstrap.php,table.sql,version.phptests/Unit/*files exist in this template yet, so no PHPUnit run is meaningful here. Validation done by checking that the rendered (post-bin/setup){ModuleName}placeholder resolves the namespace correctly — this matches the convention already used insrc/Bootstrap.phpetc.