Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .wp-env.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"testsEnvironment": false,
"port": 8889,
"core": null,
"plugins": [ "WordPress/abilities-api", "./." ],
"plugins": [ "./." ],
"config": {
"FS_METHOD": "direct",
"WP_DEBUG": true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"autoload-dev": {
"psr-4": {
"WP\\MCP\\Tests\\": [
"tests/"
"tests/phpunit/"
]
}
},
Expand Down
20 changes: 10 additions & 10 deletions docs/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ See [CONTRIBUTING.md](../../CONTRIBUTING.md#prerequisites) for full setup requir

## Test Layout

- `tests/Unit/*`: fast unit tests for pure PHP logic and MCP handlers
- `tests/Integration/*`: WordPress-integration tests that exercise filters, permissions, routing, and transport layers
- `tests/Fixtures/*`: test doubles (dummy error/observability handlers, abilities, transport)
- `tests/phpunit/Unit/*`: fast unit tests for pure PHP logic and MCP handlers
- `tests/phpunit/Integration/*`: WordPress-integration tests that exercise filters, permissions, routing, and transport layers
- `tests/phpunit/Fixtures/*`: test doubles (dummy error/observability handlers, abilities, transport)

## Running Tests

Expand All @@ -28,7 +28,7 @@ First, ensure the wp-env environment is running:
npm run wp-env:test start
```

This starts a WordPress instance at http://localhost:8888 with all required dependencies.
This starts a WordPress instance at http://localhost:8889 with all required dependencies.

### Running All Tests

Expand All @@ -49,7 +49,7 @@ You can pass PHPUnit arguments to the test script using `--`:
npm run test:php -- --filter test_execute_with_public_mcp_filtering

# Run a specific test file
npm run test:php -- tests/Unit/Handlers/ToolsHandlerCallTest.php
npm run test:php -- tests/phpunit/Unit/Handlers/ToolsHandlerCallTest.php

# Run tests matching a pattern
npm run test:php -- --filter "Tools.*"
Expand All @@ -75,12 +75,12 @@ Coverage reports will be generated:

The test suite includes fixtures for verifying observability and error handling:

**DummyObservabilityHandler** (`tests/Fixtures/DummyObservabilityHandler.php`)
**DummyObservabilityHandler** (`tests/phpunit/Fixtures/DummyObservabilityHandler.php`)
- Captures `record_event()` calls with event names, tags, and optional timing data
- Stores events in `$events` array for test assertions
- Used to verify that requests, successes, errors, and timings are properly tracked

**DummyErrorHandler** (`tests/Fixtures/DummyErrorHandler.php`)
**DummyErrorHandler** (`tests/phpunit/Fixtures/DummyErrorHandler.php`)
- Captures `log()` calls with messages, context, and error types
- Stores logs in `$logs` array for test assertions
- Used to verify error handling and logging behavior
Expand All @@ -89,9 +89,9 @@ Tests verify that error responses adhere to JSON-RPC 2.0 format: `{ jsonrpc, id,

## Writing New Tests

- Place unit tests under `tests/Unit/.../*Test.php`
- Place integration tests under `tests/Integration/.../*Test.php`
- Use fixtures in `tests/Fixtures` or create your own test doubles
- Place unit tests under `tests/phpunit/Unit/.../*Test.php`
- Place integration tests under `tests/phpunit/Integration/.../*Test.php`
- Use fixtures in `tests/phpunit/Fixtures` or create your own test doubles
- Follow the Arrange-Act-Assert (AAA) pattern
- Mock external dependencies using PHPUnit mocks
- Test files should mirror the source structure with a `Test.php` suffix
Expand Down
4 changes: 2 additions & 2 deletions includes/Transport/Infrastructure/RequestRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace WP\MCP\Transport\Infrastructure;

use WP\MCP\Infrastructure\ErrorHandling\McpErrorFactory;
use WP\MCP\Infrastructure\Observability\McpObservabilityHelperTrait;
use WP\MCP\Infrastructure\Observability\ErrorLogMcpObservabilityHandler;
use WP\McpSchema\Common\AbstractDataTransferObject;
use WP\McpSchema\Common\Content\DTO\TextContent;
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCErrorResponse;
Expand Down Expand Up @@ -289,7 +289,7 @@ private function sanitize_params_for_logging( array $params ): array {
// Filter argument keys to exclude sensitive-looking ones.
$safe_keys = array();
foreach ( array_keys( $params['arguments'] ) as $arg_key ) {
if ( McpObservabilityHelperTrait::is_sensitive_key( (string) $arg_key ) ) {
if ( ErrorLogMcpObservabilityHandler::is_sensitive_key( (string) $arg_key ) ) {
Comment thread
justlevine marked this conversation as resolved.
$safe_keys[] = '[REDACTED]';
} else {
$safe_keys[] = $arg_key;
Expand Down
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
bootstrap="tests/phpunit/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutOutputDuringTests="true"
Expand All @@ -15,10 +15,10 @@
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">./tests/Unit/</directory>
<directory suffix="Test.php">./tests/phpunit/Unit/</directory>
</testsuite>
<testsuite name="integration">
<directory suffix="Test.php">./tests/Integration/</directory>
<directory suffix="Test.php">./tests/phpunit/Integration/</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="false">
Expand Down
277 changes: 0 additions & 277 deletions tests/TestCase.php

This file was deleted.

Loading