Skip to content

testing: Bootstrap PHPUnit 10 + Brain Monkey for Free plugin unit tests #193

@parhumm

Description

@parhumm

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.dist
  • tests/bootstrap.php (unit — no WP loaded)
  • tests/bootstrap-integration.php (WP loaded via wp-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 call Monkey\setUp() before test logic; tearDown() MUST call Monkey\tearDown() after
  • Unit bootstrap MUST NOT load WordPress
  • Coverage target: ≥60% line coverage for new src/ code (research 01 §C)

Acceptance criteria

  • composer test:unit runs and exits 0 with green smoke test
  • composer test:coverage generates HTML report to tests/coverage/html/
  • SlimStatUnitTestCase available for all unit tests
  • phpunit.xml.dist defines unit and integration suites

References

  • Research 02 §1.1, §1.2 — PHPUnit + Brain Monkey
  • Research 01 §B — Recommended toolchain

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions