Download the PHP package devuri/wp-adapter without Composer
On this page you can find all versions of the php package devuri/wp-adapter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devuri/wp-adapter
More information about devuri/wp-adapter
Files in devuri/wp-adapter
Package wp-adapter
Short Description WordPress adapter contracts and in-memory testing doubles for clean, testable plugin development.
License MIT
Informations about the package wp-adapter
WP Adapter
WordPress adapter contracts and in-memory testing doubles for clean, testable plugin development.
The problem this solves
WordPress plugins commonly call get_option(), add_action(), and wp_remote_post() directly inside business logic. That makes the logic impossible to unit test without bootstrapping WordPress, and it makes the plugin hard to reason about.
WP Adapter gives us a thin set of contracts for common WordPress APIs and matching in-memory implementations for tests. Our plugin code depends only on the contracts. WordPress stays at the edge.
In production we pass the WordPress adapters. In tests we pass the in-memory fakes. No mocks. No bootstrapping WordPress.
Our plugin must follow the boundary rule
This package cannot help us if our business logic calls WordPress functions directly. The adapters are only useful when our plugin is structured so that service classes receive their dependencies through the constructor as contracts.
The rule: WordPress function calls (get_option, add_action, wp_remote_post, etc.) belong only in the thin adapter classes that implement the contracts. Every other class must call only the interface, never WordPress.
If we call get_option() inside a service, that service requires WordPress to exist and cannot be unit tested. The testing adapters in this package will have no effect.
See docs/testing-guide.md for the full structure, a wrong-vs-right example, PHPUnit setup, and a checklist.
Installation
Install as a dev dependency during development:
Copy the source into our plugin at build time:
This copies src/ and psr/log into lib/wp-adapter/ inside our plugin. Load it from our plugin's main file:
Strip vendor/ before distributing. lib/ ships with the plugin. See Direct-load distribution for the full workflow.
Wiring production adapters
Unit testing without WordPress
Swap in the in-memory testing adapters. No WordPress bootstrap required.
PHPUnit bootstrap (tests/bootstrap.php)
One line. Composer's autoloader includes devuri/wp-adapter and psr/log. All contracts and testing adapters are available. No WordPress, no WP_TESTS_DIR.
PHPUnit config (phpunit.xml.dist)
defaultTestSuite="Unit" ensures vendor/bin/phpunit never loads the integration suite. Integration tests (those that require WordPress) must be marked @group integration and run explicitly:
See examples/plugin-wiring/ for a complete, runnable example with service class, plugin class, and tests.
Testing adapters
All testing adapters live in AdapterKit\Core\Testing\ and are public, versioned API.
InMemoryOptionStorage
InMemoryTransientStorage + FrozenClock
MockHttpClient
RecordingHooks
RecordingLogger
MockEnvironment
Contracts
Six interfaces in AdapterKit\Core\Contracts\. Our plugin code depends only on these.
| Contract | Production adapter | Testing adapter |
|---|---|---|
HooksInterface |
WordPressHooks |
RecordingHooks |
OptionStorageInterface |
WordPressOptionStorage |
InMemoryOptionStorage |
TransientStorageInterface |
WordPressTransientStorage |
InMemoryTransientStorage |
EnvironmentInterface |
WordPressEnvironment |
MockEnvironment |
HttpClientInterface |
WordPressHttpClient |
MockHttpClient |
ClockInterface |
SystemClock |
FrozenClock |
LoggerInterface is Psr\Log\LoggerInterface. NullLogger and WordPressDebugLogger are the production implementations.
Shared value types
PluginContext — immutable plugin metadata populated once at bootstrap.
Result — shared return type for service methods.
KeyBuilder — prevents option/transient/hook naming drift.
Direct-load distribution
WordPress plugins are distributed as ZIP files without a Composer runtime. WP Adapter supports this out of the box.
Development workflow:
wp-adapter-copy copies src/ and a PHP 7.4-safe copy of psr/log into lib/wp-adapter/. The init.php entry point registers two PSR-4 autoloaders — one for AdapterKit\Core\ and one for Psr\Log\ — so no Composer is needed on the end user's server.
Do not use a class_exists guard:
Namespace-per-plugin scoping is deferred to a future build step.
Requirements
| PHP | 7.4, 8.0, 8.1, 8.2 |
| WordPress | No minimum enforced |
| Dependencies | psr/log ^1.1 (runtime) |
The package is deliberately PHP 7.4 compatible throughout. mixed type hints, constructor property promotion, union types, and all other PHP 8.0+ syntax are forbidden in src/.
Further reading
- docs/testing-guide.md boundary rule, wrong-vs-right examples, PHPUnit setup, checklist
- docs/architecture.md three-layer design, contract table, PSR adoption scope
- docs/direct-load.md full direct-load distribution workflow
- docs/compatibility.md PHP version matrix, forbidden syntax, PSR-3 pin rationale
- examples/plugin-wiring/ complete example with service, plugin class, and unit tests
License
This project is licensed under the MIT License. See the LICENSE file for details.