|
| 1 | +# Codeception Module for PHP OpenAPI Mock Server - Project Context |
| 2 | + |
| 3 | +This directory contains a Codeception module designed to provide easy access to and control over the [PHP OpenAPI Mock Server](https://github.com/WebProject-xyz/php-openapi-mock-server). |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +* **Type:** PHP Library / Codeception Module |
| 8 | +* **Purpose:** Orchestrate a standalone OpenAPI mock server during automated tests and provide high-level actions for test scenarios. |
| 9 | +* **Key Technologies:** |
| 10 | + * **Language:** PHP 8.3+ (PSR-12, Symfony, and Risky rulesets) |
| 11 | + * **Testing:** Codeception 5.x |
| 12 | + * **Process Management:** Symfony Process |
| 13 | + * **CI/CD:** GitHub Actions (configured in `.github/workflows/ci.yml`) |
| 14 | + * **Automation:** GrumPHP (commit hooks), PHP-CS-Fixer, PHPStan (Level 8) |
| 15 | + |
| 16 | +## Architecture |
| 17 | + |
| 18 | +The module `WebProject\Codeception\Module\OpenApiServerMock` acts as a **Helper Module**. |
| 19 | +- **Lifecycle Management:** It starts a PHP built-in server running the `openapi-mock-server` binary before the suite and stops it after. |
| 20 | +- **Auto-Detection:** It attempts to locate the mock server automatically via class reflection or directory traversal. |
| 21 | +- **Dynamic Control:** It communicates with the mock server via custom HTTP headers (`X-OpenApi-Mock-Active`, `X-OpenApi-Mock-StatusCode`, `X-OpenApi-Mock-Example`) to manipulate mock responses on the fly. |
| 22 | +- **Dependencies:** Designed to be used alongside `REST` and `PhpBrowser` modules. |
| 23 | + |
| 24 | +## Building and Running |
| 25 | + |
| 26 | +### Prerequisites |
| 27 | +* PHP 8.3 or higher. |
| 28 | +* Composer. |
| 29 | + |
| 30 | +### Setup |
| 31 | +```bash |
| 32 | +composer install |
| 33 | +vendor/bin/codecept build # Generate Tester actions |
| 34 | +``` |
| 35 | + |
| 36 | +### Testing |
| 37 | +```bash |
| 38 | +composer test # Run all tests |
| 39 | +vendor/bin/codecept run Acceptance # Run acceptance tests specifically |
| 40 | +``` |
| 41 | + |
| 42 | +### Static Analysis and Linting |
| 43 | +```bash |
| 44 | +composer stan # Run PHPStan (Level 8) |
| 45 | +composer cs:check # Check coding standards |
| 46 | +composer cs:fix # Fix coding standards |
| 47 | +``` |
| 48 | + |
| 49 | +## Development Conventions |
| 50 | + |
| 51 | +* **Namespaces:** |
| 52 | + * Source: `WebProject\Codeception\Module\` |
| 53 | + * Tests: `WebProject\Codeception\Module\Tests\` |
| 54 | +* **Coding Standard:** Strict adherence to PSR-12 and Symfony coding styles via PHP-CS-Fixer. |
| 55 | +* **Strict Typing:** `declare(strict_types=1);` is required in all PHP files. |
| 56 | +* **Type Safety:** PHPStan Level 8 is enforced. Avoid `mixed` where possible; use specific iterable types in PHPDoc. |
| 57 | +* **Commit Hooks:** GrumPHP runs `php-cs-fixer`, `phpstan`, and `codeception` on every commit. |
| 58 | + |
| 59 | +## Key Files |
| 60 | + |
| 61 | +* `src/OpenApiServerMock.php`: The main module logic. |
| 62 | +* `tests/Acceptance/MockServerCest.php`: Main acceptance tests for the module. |
| 63 | +* `codeception.yml`: Global Codeception configuration. |
| 64 | +* `phpstan.neon`: PHPStan configuration (Level 8). |
| 65 | +* `.php-cs-fixer.php`: Coding style rules. |
| 66 | +* `grumphp.yml`: Automation task definitions. |
0 commit comments