Skip to content
Open
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
10 changes: 5 additions & 5 deletions docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ Follow the steps in [Creating a New Experiment](#creating-a-new-experiment) abov

### 3. Write Tests

Create unit tests in `tests/Unit/` for your experiment:
Add or update tests for your experiment in the existing integration suite under `tests/Integration/`:

```php
<?php
namespace WordPress\AI\Tests\Unit\Experiments\My_Experiment;
namespace WordPress\AI\Tests\Integration\Includes\Experiments\My_Experiment;

use WordPress\AI\Experiments\My_Experiment\My_Experiment;
use PHPUnit\Framework\TestCase;
use WP_UnitTestCase;

class My_Experiment_Test extends TestCase {
class My_Experiment_Test extends WP_UnitTestCase {
public function test_experiment_metadata() {
$this->assertEquals( 'my-experiment', My_Experiment::get_id() );

Expand All @@ -326,7 +326,7 @@ class My_Experiment_Test extends TestCase {
Before submitting, ensure all quality checks pass. See [CONTRIBUTING.md](../CONTRIBUTING.md) for the complete list of required checks including:
- Coding standards validation
- Static analysis
- Unit tests
- Integration tests

### 5. Submit Pull Request

Expand Down
49 changes: 11 additions & 38 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,23 @@ This document outlines the testing philosophy and strategy for the AI plugin, ad

**Purpose**: Test pure functions and business logic in isolation, without loading the WordPress environment.

**Location**: `tests/Unit/`

**Example Test Suite**: `tests/Unit/Includes/FeatureCollectionTest.php`

```php
class FeatureCollectionTest extends TestCase {

/**
* Test that a feature can be registered.
*/
public function test_register_feature() {
$collection = new Feature_Collection();
$feature = new Mock_Feature( 'test-feature' );

$this->assertTrue( $collection->register_feature( $feature ) );
$this->assertTrue( $collection->has_feature( 'test-feature' ) );
}

// ... other unit tests for Feature_Collection ...
}
```

### 2. Integration Tests (WordPress + Plugin Interactions)

**Purpose**: Test interactions between different parts of the plugin, and between the plugin and WordPress core, database, or other plugin components. These tests run within a WordPress test environment.

**Location**: `tests/Integration/`

**Example Test Suite**: `tests/Integration/Includes/Feature_RegistryTest.php`
**Example Test Suite**: `tests/Integration/Includes/BootstrapTest.php`

```php
class Feature_Registry_Test extends WP_UnitTestCase {
class BootstrapTest extends WP_UnitTestCase {

/**
* Test that registry returns singleton.
* Test that the plugin bootstrap file exists.
*/
public function test_instance_returns_singleton() {
$instance1 = Feature_Registry::instance();
$instance2 = Feature_Registry::instance();

$this->assertSame( $instance1, $instance2, 'Feature_Registry should return the same singleton instance' );
public function test_bootstrap_file_exists() {
$this->assertFileExists( dirname( __DIR__, 3 ) . '/includes/bootstrap.php' );
}

// ... other integration tests for Feature_Registry ...
}
```

Expand All @@ -89,18 +62,18 @@ While specific examples are provided in the "Post Duplication Feature" strategy,
composer test

# Run static analysis (fast, focuses on type safety)
composer stan
composer phpstan

# Run only unit tests (fast - run frequently)
vendor/bin/phpunit --testsuite "AI Plugin Unit Tests"
# Run the current PHPUnit suite defined in phpunit.xml.dist
vendor/bin/phpunit -c phpunit.xml.dist

# Run only integration tests (slower - run before commit)
vendor/bin/phpunit --testsuite "AI Plugin Integration Tests"
# Run the current integration suite directly
vendor/bin/phpunit -c phpunit.xml.dist --testsuite integration
```

### CI/CD Pipeline

Automated testing in a CI/CD pipeline would involve running both unit and integration tests on every push and pull request, potentially across a matrix of PHP and WordPress versions.
Automated testing in CI should run the currently configured integration and end-to-end suites on every push and pull request. If a dedicated unit test suite is introduced later, it should be added to the pipeline as well.

---

Expand Down
Loading