Add PHPUnit test suite, PSR-4 refactor, lint+test CI jobs (v1.3.1)
Some checks failed
Create Release Package / PHP Lint (push) Successful in 47s
Create Release Package / test (push) Failing after 53s
Create Release Package / build-release (push) Has been skipped

- 57 unit tests covering ProductType, StockManager, CartHandler, Plugin,
  Admin/ProductData, Admin/Settings using Brain Monkey + Mockery
- WooCommerce class stubs for testing without WP installation
- PHP lint and test jobs in release workflow (test gate blocks release)
- PSR-4 namespace change: WC_Composable_Product -> Magdev\WcComposableProduct
- PascalCase filenames for all classes under includes/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 13:08:22 +01:00
parent ea2261d8d7
commit a7d6a57f01
24 changed files with 3415 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ This project is 100% AI-generated ("vibe-coded") using Claude.AI.
- **Styling:** Custom CSS
- **Dependencies:** Composer
- **i18n:** WordPress i18n (.pot/.po/.mo), text domain: `wc-composable-product`
- **Testing:** PHPUnit 9.6 + Brain Monkey 2.7 + Mockery 1.6
- **CI/CD:** Gitea Actions (`.gitea/workflows/release.yml`)
## Project Structure
@@ -45,10 +46,16 @@ wc-composable-product/
│ └── StockManager.php # Stock management & inventory tracking
├── languages/ # Translation files (.pot, .po, .mo)
├── releases/ # Release packages (gitignored)
├── tests/
│ ├── bootstrap.php # Test environment setup (constants, stubs)
│ ├── TestCase.php # Base test case with Brain Monkey
│ ├── stubs/ # Minimal WooCommerce class stubs
│ └── Unit/ # PHPUnit unit tests
├── templates/
│ └── product-selector.twig # Frontend selection interface
├── vendor/ # Composer dependencies (gitignored, included in releases)
├── composer.json
├── phpunit.xml.dist # PHPUnit configuration
└── wc-composable-product.php # Main plugin file
```
@@ -133,11 +140,17 @@ Compile .po to .mo: `for po in languages/*.po; do msgfmt -o "${po%.po}.mo" "$po"
WordPress requires compiled .mo files — .po files alone are insufficient.
## Testing
Run unit tests: `vendor/bin/phpunit --testdox`
Tests use **Brain Monkey** to mock WordPress/WooCommerce functions without a full WP installation. WooCommerce classes (`WC_Product`, `WC_Settings_Page`, etc.) are provided as minimal stubs in `tests/stubs/` so PHP can parse `extends` declarations. The release workflow runs tests before building — a failing test blocks the release.
## Release Workflow
### Automated (Gitea CI/CD)
Push an annotated tag (`v*`) to trigger the workflow. It installs PHP 8.3, production Composer deps, compiles translations, verifies version matches tag, creates ZIP with checksums, and publishes a Gitea release.
Push an annotated tag (`v*`) to trigger the workflow. It first runs the PHPUnit test suite, then installs PHP 8.3, production Composer deps, compiles translations, verifies version matches tag, creates ZIP with checksums, and publishes a Gitea release. Tests must pass before the release package is built.
### Manual