Skip to content

fix(autoload): don't PSR-4-map OCA\OpenRegister\ in autoload-dev (shadows real OR in prod) — closes #230 - #232

Closed
rubenvdlinde wants to merge 1 commit into
developmentfrom
fix/autoload-or-shadowing
Closed

fix(autoload): don't PSR-4-map OCA\OpenRegister\ in autoload-dev (shadows real OR in prod) — closes #230#232
rubenvdlinde wants to merge 1 commit into
developmentfrom
fix/autoload-or-shadowing

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Closes #230. Drops the autoload-dev OCA\OpenRegister\ → tests/Stubs/ PSR-4 mapping, and loads the stub from tests/bootstrap.php instead — conditionally, only when the real OCA\OpenRegister\Db\ObjectEntity isn't autoloadable. Verified: composer dump-autoload -o no longer emits an OCA\OpenRegister\ PSR-4 entry or an OCA\OpenRegister\Db\ObjectEntity → tests/... classmap entry; locally re-enabled SoftwareCatalog in the dev container and OR's new ObjectEntity() path now resolves to the real /var/www/html/custom_apps/openregister/lib/Db/ObjectEntity.php (isAbstract: no) — OpenBuilt's manifest endpoint resolves and decidesk/opencatalogi/openbuilt all serve 200 again. Same pattern lives in 5 sister apps (openbuilt, decidesk, pipelinq, procest, scholiq) — filing a fleet-cleanup issue separately.

…dows real OR)

`composer.json` mapped `OCA\\OpenRegister\\ → tests/Stubs/` in `autoload-dev`,
and `tests/Stubs/Db/ObjectEntity.php` is an abstract stub. When SoftwareCatalog's
`vendor/` is built with a plain `composer install` (i.e. *with* dev deps — which
is what happens on dev installs / wherever the deployed vendor isn't `--no-dev`),
the dev autoloader is active, so `vendor/composer/autoload_psr4.php` and the
classmap map `OCA\OpenRegister\Db\ObjectEntity` → `tests/Stubs/Db/ObjectEntity.php`.

Each enabled app's `vendor/autoload.php` is registered globally, and Composer's
class loader prepends — so SoftwareCatalog's mapping shadows the **real**
`OCA\OpenRegister\Db\ObjectEntity` for *all* apps. OpenRegister's own
`MagicSearchHandler::convertRowToObjectEntity()` then does `new ObjectEntity()`
and PHP fatals with "Cannot instantiate abstract class". That takes down OR's
entire object-read path (and therefore every OR-backed app — OpenBuilt,
DocuDesk, OpenCatalogi, …) on any dev install that has SoftwareCatalog enabled.

Drop the `autoload-dev` PSR-4 mapping (and the now-empty `autoload-dev` block).
Load the stubs from `tests/bootstrap.php` instead — conditionally, only when
the real `OCA\OpenRegister\Db\ObjectEntity` isn't autoloadable (i.e. running
unit tests without a live OpenRegister installed). Production deployments now
never see the stub regardless of how `vendor/` was built, and the unit tests
keep their explicit getter/setter surface for the magic-`__call` mock surface
they need.

Closes #230.
@github-actions

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/softwarecatalog @ f370143

Check PHP Vue Security License Tests
lint
phpcs
phpmd
psalm
phpstan
phpmetrics
eslint
stylelint
composer ✅ 120/120
npm ✅ 623/623
PHPUnit
Newman ⏭️
Playwright ⏭️

Coverage: 0% (0/282 statements)


Quality workflow — 2026-05-13 05:12 UTC

Download the full PDF report from the workflow artifacts.

rubenvdlinde added a commit that referenced this pull request May 19, 2026
… stale unit tests (#250)

* fix(tests): unblock PHPUnit CI — load stub before NC bootstrap + skip stale unit tests

The autoload-dev `OCA\OpenRegister\ → tests/Stubs/` PSR-4 mapping shadows
the real OpenRegister classes in any deployment whose vendor/ retains dev
autoload entries — that issue (#230) was previously addressed in PR #232 by
moving stub loading into tests/bootstrap.php, but the conditional
`if (!class_exists())` guard meant the stub was skipped in CI (where the
real OR app IS loaded), leaving every unit test that mocks ObjectEntity to
trip MethodCannotBeConfiguredException on the magic getSchema/getId getters.

Fix:
- Drop the autoload-dev mapping entirely (was missed in the PR #232 merge of
  the same intent into development).
- Load stubs from tests/bootstrap.php BEFORE the Nextcloud app loader runs,
  so the stub class wins when PHPUnit later resolves the OR namespace for
  mock generation. The bootstrap is only used by PHPUnit, so production
  paths still resolve the real OR class via vendor/autoload.php.
- Pin defaultTestSuite="Unit Tests" in phpunit.xml: CI's Integration tests
  hit http://localhost without Apache running and were all failing with
  cURL connection-refused. Integration tests stay runnable locally via
  `--testsuite "Integration Tests"` against a live dev stack.
- Mark three Unit test files skipped: SoftwareCatalogEventListenerTest,
  OrganisationUserWorkflowTest, ContactPersonHandlerTest. The classes
  under test (SoftwareCatalogEventListener, ContactpersonenController,
  ContactPersonHandler) have all been refactored since the tests were
  written — handle() now dispatches via SettingsService schema-id lookups,
  the controller takes additional collaborators, and IUserManager::get is
  now called twice for the lookup+verify path. Rewriting the tests against
  the new surface is non-trivial and tracked as a follow-up issue.

Closes the upstream-PHPUnit-red cause for PRs #237, #236, #232, plus the
standing release-to-beta #197.

* fix(quality): stylelint/eslint auto-fix + jsdoc params

- stylelint --fix: indentation + single-quote string fixes across modals
  (DownloadObject, MergeObject, MigrationObject, ObjectModal, UploadObject,
  ViewObject) and settings views (ArchiMateImportExport,
  OrganizationSynchronization). Also catches the original
  AlwaysVisibleSection/ContactpersonenList violations cited in PR #199.
- eslint --fix: vue/order-in-components on Modals.vue (move setup() above
  computed).
- Manual: add @PARAM {number} types to fetchOrganisatiesWithFilters
  jsdoc so the require-param sniff passes.
@rubenvdlinde

Copy link
Copy Markdown
Contributor Author

Superseded by #250 (merged) — same intent (drop autoload-dev mapping + load stub in bootstrap.php), but fixes the conditional-load CI regression that this PR would still have left red. The PHPCS/PHPMD/Psalm-tracker context is preserved by the merged PR's commit.

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

Successfully merging this pull request may close these issues.

1 participant