fix(connector): tighten site regex and split initialize for testability#35
Merged
Conversation
b59324d to
79f63e8
Compare
Extract validateSite, resolveGlobalsPath, prepareCliEnvironment, and verifyDatabase as protected helpers so the non-bootstrap-dependent parts (site regex, globals.php location, $_SERVER/$_GET defaults, post-bootstrap DB checks) can be unit-tested without an OpenEMR runtime. The require_once stays inline in initialize() so globals.php executes in the same local scope as before. Tests reach the protected helpers via OpenEMRConnectorTestable, a test-only subclass that exposes each one as a call*() pass-through, plus Reflection for the already-initialized short-circuit case. Also tighten the site-validation regex with the D modifier — without it, PHP's $ anchor matches end-of-string OR just before a trailing newline, so "default\n" would slip past validation. The new test cases surfaced this. Closes #10 Assisted-by: Claude Code
79f63e8 to
7c25a29
Compare
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.
Fixes #10.
Summary
validateSite,resolveGlobalsPath,prepareCliEnvironment, andverifyDatabasefromOpenEMRConnector::initializeasprotectedhelpers so the non-bootstrap-dependent pieces can be unit-tested without an OpenEMR runtime.require_once globals.phpstays inline ininitialize()so OpenEMR's bootstrap executes in the same local scope as before.Dmodifier — without it, PHP's$anchor matches end-of-string OR just before a trailing newline, so--site=default\nwould slip past validation. Surfaced by the new tests.OpenEMRConnectorTestable, a test-only subclass that exposes them ascall*()pass-throughs.Coverage added
resolveGlobalsPath: present, trailing-slash-tolerant, missing.prepareCliEnvironment: defaults applied; existing$_SERVERvars preserved;$_GET[site]always overwritten.verifyDatabase: missing$GLOBALS['dbh'], false$GLOBALS['dbh'], missingsqlQuery()function.initialize()short-circuit when already initialized.Test plan
composer check(php-lint, phpcs, phpstan level 9, rector) clean.composer phpunit— 77 tests, 231 assertions, all passing.task dev:start && task smoke— admin-unlock end-to-end against the dev container, confirming the inlinedrequire_oncestill bootstraps OpenEMR correctly (OK: unlocked admin).