Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/guides/testing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,15 @@ namespace mod_myplugin;

There are several best practices, suggestions, and things to avoid which you should consider when writing unit tests. Some of these are described below.

### Respect encapsulation

As a general principle, testing should not compromise encapsulation. Most behavior should be verifiable through public methods without need of using reflection. If substantial logic exists only behind private or protected methods, this may indicate that responsibilities should be extracted into a separate class with own public API.

- Avoid changing API visibility in core code solely to simplify testing.
Comment on lines +633 to +637
- Prefer testing public APIs, as this use internal implementation details while preserving encapsulation.
Comment on lines +635 to +638
- When protected functionality requires direct testing, use inheritance-based approaches.
- Using reflection may be considered as a last resort.

### Using the magic `::class` constant {/* #using-the-magic-class-constant */}

PHP supports the use of a magic `::class` constant to correctly and consistently define class names. This can be used in a range of situations, including:
Expand Down
Loading