You've already forked wp-prometheus
feat: Add comprehensive PHPUnit test suite and CI/CD test gating (v0.5.0)
189 tests across 8 test classes covering all core plugin classes: CustomMetricBuilder, StorageFactory, Authentication, DashboardProvider, RuntimeCollector, Installer, Collector, and MetricsEndpoint. Added test job to Gitea release workflow that gates build-release. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
40
README.md
40
README.md
@@ -222,6 +222,46 @@ add_action( 'wp_prometheus_register_dashboards', function( $provider ) {
|
||||
|
||||
## Development
|
||||
|
||||
### Testing
|
||||
|
||||
The plugin includes a comprehensive PHPUnit test suite with 189 tests covering all core classes.
|
||||
|
||||
```bash
|
||||
# Install dependencies (including dev)
|
||||
composer install
|
||||
|
||||
# Run the full test suite
|
||||
composer test
|
||||
```
|
||||
|
||||
#### Test Architecture
|
||||
|
||||
Tests use [php-mock/php-mock-phpunit](https://github.com/php-mock/php-mock-phpunit) to mock WordPress functions called from namespaced plugin code, and a `GlobalFunctionState` helper for controlling global-scope function stubs (authentication, options, conditionals).
|
||||
|
||||
```
|
||||
tests/
|
||||
├── bootstrap.php # WP constants + function stubs
|
||||
├── Helpers/
|
||||
│ └── GlobalFunctionState.php # Controllable state for stubs
|
||||
└── Unit/
|
||||
├── TestCase.php # Base class with PHPMock trait
|
||||
├── AuthenticationTest.php # Bearer/query auth, header extraction
|
||||
├── InstallerTest.php # Activate, deactivate, uninstall
|
||||
├── Metrics/
|
||||
│ ├── CustomMetricBuilderTest.php # Validation, CRUD, import/export
|
||||
│ ├── RuntimeCollectorTest.php # Endpoint normalization, histograms
|
||||
│ ├── StorageFactoryTest.php # Adapter config, env vars, connections
|
||||
│ └── CollectorTest.php # Registry, register_*, render
|
||||
├── Admin/
|
||||
│ └── DashboardProviderTest.php # Registration, path security
|
||||
└── Endpoint/
|
||||
└── MetricsEndpointTest.php # Rewrite rules, request routing
|
||||
```
|
||||
|
||||
#### CI/CD Integration
|
||||
|
||||
Tests run automatically in the Gitea CI/CD pipeline before release builds. A failing test suite blocks the release.
|
||||
|
||||
### Build for Release
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user