-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Summary
Set up PHPUnit 10 + Brain Monkey 2.x as the unit test framework for wp-slimstat, enabling fast (<30s) WordPress-free unit tests for all PHP source classes.
Motivation
No PHP unit test infrastructure exists for the Free plugin. Every unit-testable bug (consent logic, bot detection, visit_id generation) currently requires manual testing or a user report.
Dependencies
None.
Implementation
Files to create
phpunit.xml.disttests/bootstrap.php(unit — no WP loaded)tests/bootstrap-integration.php(WP loaded viawp-tests-config.php)tests/unit/SmokeTest.php- Base class:
tests/unit/SlimStatUnitTestCase.php
composer.json require-dev
```json
{
"phpunit/phpunit": "^10.5",
"brain/monkey": "^2.6",
"mockery/mockery": "^1.6"
}
```
composer.json scripts
```json
{
"test:unit": "phpunit --testsuite unit",
"test:integration": "phpunit --testsuite integration",
"test:all": "phpunit",
"test:coverage": "phpunit --coverage-html tests/coverage/html --coverage-clover tests/coverage/clover.xml"
}
```
phpunit.xml.dist
```xml
tests/unit
tests/integration
src/
```
Base test class
```php
abstract class SlimStatUnitTestCase extends TestCase {
protected function setUp(): void { parent::setUp(); Monkey\setUp(); }
protected function tearDown(): void { Monkey\tearDown(); parent::tearDown(); }
}
```
Standards
- PHPUnit 10.x for PHP 8.1+ (research 02 §1.1)
- Brain Monkey 2.6+ (research 02 §1.2)
setUp()MUST callMonkey\setUp()before test logic;tearDown()MUST callMonkey\tearDown()after- Unit bootstrap MUST NOT load WordPress
- Coverage target: ≥60% line coverage for new
src/code (research 01 §C)
Acceptance criteria
-
composer test:unitruns and exits 0 with green smoke test -
composer test:coveragegenerates HTML report totests/coverage/html/ -
SlimStatUnitTestCaseavailable for all unit tests -
phpunit.xml.distdefinesunitandintegrationsuites
References
- Research 02 §1.1, §1.2 — PHPUnit + Brain Monkey
- Research 01 §B — Recommended toolchain
Metadata
Metadata
Assignees
Type
Projects
Status