code-snippets icon indicating copy to clipboard operation
code-snippets copied to clipboard

feat: Add PHPUnit test suite

Open imantsk opened this issue 2 months ago • 0 comments

Summary

Add and configure a PHPUnit-based test suite for the plugin, and add tests covering: (A) REST API performance and pagination behavior, and (B) snippet-ops functions (create/update/delete/import/export edge cases).

Goals

  • Configure PHPUnit and the WordPress test harness so tests can run locally and in CI.
  • Add unit/integration tests that assert REST API pagination headers, page contents, and out-of-range behavior.
  • Add tests for snippet-ops functions to increase coverage and guard against regressions.
  • Add a lightweight performance test that asserts REST API responses meet a baseline latency under test conditions.

Tasks

  • [x] Create phpunit.xml (or update existing) with proper bootstrap and test suite configuration.
  • [ ] Add composer dev dependencies (phpunit, brain/brain or WP test helpers if needed) and document install steps.
  • [ ] Add tests under tests/ (phpunit):
    • [ ] tests/RestApiTest.php — covers GET /code-snippets/v1/snippets pagination, headers X-WP-Total & X-WP-TotalPages, page contents differ, and out-of-range page behavior (empty array or 400 depending on API contract).
    • [ ] tests/SnippetOpsTest.php — covers snippet-ops create/update/delete/export/import edge cases, invalid input handling, and permission checks.
  • [ ] Add a GitHub Actions workflow phpunit.yml to run tests on PRs and master/core branch.
  • [ ] Document local setup and CI requirements in CONTRIBUTING.md or README (DB/WP test harness setup).

Acceptance criteria

  • PHPUnit runs locally and in CI (GitHub Actions) and returns green for the test suite.
  • REST pagination tests reliably assert headers and per-page content differences.
  • snippet-ops tests cover the major create/update/delete/export/import flows and edge cases.

Notes / Implementation details

  • The plugin already uses WP_REST_Controller style controllers; prefer using rest_do_request() + WP_REST_Request in tests where possible to avoid network-dependant flakes.
  • For performance tests, prefer a simple synthetic test that measures rest_do_request() response time under a short loop instead of full HTTP requests; move to full HTTP tests only if necessary in E2E suite.

Environment / Setup

  • Provide steps (or link to existing tests/install.sh) for bootstrapping the WP test environment (WP test suite, DB, WP constants).

Please assign /cc whoever is best to implement the test infra and break this into smaller PRs if needed.

imantsk avatar Oct 22 '25 13:10 imantsk