diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index 0c11fb42..ae440168 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -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 code in the existing test suite under `tests/Integration/`: ```php assertEquals( 'my-experiment', My_Experiment::get_id() ); @@ -327,6 +327,7 @@ Before submitting, ensure all quality checks pass. See [CONTRIBUTING.md](../CONT - Coding standards validation - Static analysis - Unit tests +- E2E tests ### 5. Submit Pull Request diff --git a/docs/TESTING.md b/docs/TESTING.md index aefd0966..708699a4 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -17,58 +17,27 @@ This document outlines the testing philosophy and strategy for the AI plugin, ad ## Test Categories -### 1. Unit Tests (Logic Layer) - -**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) +### 1. Unit 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/MainTest.php` ```php -class Feature_Registry_Test extends WP_UnitTestCase { +class MainTest extends WP_UnitTestCase { /** - * Test that registry returns singleton. + * Test that the plugin main 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_main_file_exists() { + $this->assertFileExists( dirname( __DIR__, 3 ) . '/includes/Main.php' ); } - - // ... other integration tests for Feature_Registry ... } ``` -### 3. Edge Cases and Error Scenarios +### 2. Edge Cases and Error Scenarios While specific examples are provided in the "Post Duplication Feature" strategy, for our plugin, we would focus on: @@ -89,18 +58,16 @@ 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" ``` ### 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 unit and end-to-end suites on every push and pull request. ---