Skip to content

Add unit test support for plugins#4

Open
saeedvaziry wants to merge 1 commit into
mainfrom
add-unit-test-support
Open

Add unit test support for plugins#4
saeedvaziry wants to merge 1 commit into
mainfrom
add-unit-test-support

Conversation

@saeedvaziry

Copy link
Copy Markdown
Member

What

Adds PHP unit-testing support for plugins. Plugin code compiles against host VitoDeploy classes (App\Plugins\*, App\SiteFeatures\Action, App\Models\*, the SSH facade) and the host's Tests\TestCase, so tests can't run standalone in this repo. This wires up a runner that stages each plugin into a checkout of vitodeploy/vito and runs the host's PHPUnit there — giving tests the real host classes and the auto-provisioned $this->server / $this->site.

Changes

  • scripts/test.mjs — for each plugin with a tests/ dir: derives the host path from the manifest namespace, stages the plugin into app/Vito/Plugins/<Vendor>/<Name>/ and its tests into tests/Feature/Plugins/<Vendor>/<Name>/, runs the host's PHPUnit scoped to that dir, then cleans up (leaves zero residue). Exposed as npm test.
  • .github/workflows/test.yml — required PR check (read-only token, same trust model as validate): checks out the host at 4.x, composer install, runs the changed plugins' tests. Failure blocks merge.
  • Example tests for all three plugins (octane, reverb, tiny-file-manager) + a hello-world starter template.
  • Docs — "Test your plugin" section in CONTRIBUTING.md; decision recorded in DESIGN.md.

Tests are opt-in per plugin (a plugin with no tests/ is reported as skipped, not failed) but required when present. tests/ is already excluded from the published artifact, so test files never ship.

Notes for reviewers

  • The host uses PHPUnit, not Pestpestphp/pest isn't a direct dep of vitodeploy/vito and there's no pest binary, so tests are class-based extending Tests\TestCase, matching the host's actual tests/Feature convention.
  • A real plugin bug surfaced: Octane Enable::handle() renders view('ssh.services.webserver.nginx.vhost-blocks.laravel-octane'), which neither the plugin nor the host ships — a full enable throws View not found. The Octane example test is scoped to the parts the Action owns (validation, active() guard), with the vhost-view dependency documented in a comment. Worth a separate follow-up.
  • Host ref is pinned to 4.x; add a matrix over ref to also gate an older line.

Verification

$ VITO_PATH=/path/to/vito node scripts/test.mjs
✓ laravel-octane-plugin
✓ laravel-reverb-plugin
✓ tiny-file-manager-plugin
3 plugin(s) tested, all passing.

validate and pack --dry-run still pass; pack output confirmed to exclude tests/.

Plugin PHP compiles against host VitoDeploy classes (App\Plugins\*,
App\SiteFeatures\Action, App\Models\*, the SSH facade) and the host's
Tests\TestCase, so tests can't run standalone in this repo. Add a runner that
stages each plugin and its tests into a checkout of vitodeploy/vito and runs the
host's PHPUnit there.

- scripts/test.mjs: stage plugin -> app/Vito/Plugins/<Vendor>/<Name>/ and its
  tests -> tests/Feature/Plugins/<Vendor>/<Name>/, run host PHPUnit scoped to
  that dir, clean up. Opt-in per plugin (no tests/ = skipped), required when
  present. Wired up as `npm test`.
- .github/workflows/test.yml: required PR check (read-only, like validate);
  checks out the host at 4.x, composer install, runs changed plugins' tests.
- Example tests for all three plugins + a hello-world starter template.
- CONTRIBUTING.md "Test your plugin" section; DESIGN.md decision recorded.

tests/ is already excluded from the published artifact, so test files never ship.
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