Skip to content

feat: Add PHPUnit test suite #270

@imantsk

Description

@imantsk

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

  • 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.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions