PHPackages                             turgutsaricam/phpunit-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. turgutsaricam/phpunit-tools

ActiveLibrary[Testing &amp; Quality](/categories/testing)

turgutsaricam/phpunit-tools
===========================

Tools used with PHPUnit to make some common operations easy

v3.0.3(4y ago)0302[1 PRs](https://github.com/turgutsaricam/phpunit-tools/pulls)PHPPHP &gt;=7.2CI failing

Since Jul 29Pushed 3mo agoCompare

[ Source](https://github.com/turgutsaricam/phpunit-tools)[ Packagist](https://packagist.org/packages/turgutsaricam/phpunit-tools)[ RSS](/packages/turgutsaricam-phpunit-tools/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (2)Versions (11)Used By (0)

phpunit-tools
=============

[](#phpunit-tools)

This repository contains tools that are commonly needed to perform unit and UI tests using PHPUnit with code coverage.

Coverage Package
================

[](#coverage-package)

This package contains `CoverageHandler` and `ReportGenerator` classes. `CoverageHandler` is responsible for listening to `$_POST`, `$_GET`, and `$_POST` arrays for a hint signaling that code coverage should be enabled. When the class retrieves the hint, it starts code coverage and dumps the coverage data into the defined directory. `ReportGenerator` is responsible for generating code coverage reports from the code coverage data dumped by `CoverageHandler`. It can generate HTML and Clover reports.

CoverageHandler
---------------

[](#coveragehandler)

Note the following items for this class to work properly

- Xdebug extension of PHP must be enabled in the server of the web site in which the tests are performed.
- Create a file named as `start-coverage.php` and create an instance of `CoverageHandler` in this file.
- This file must be injected using `auto_prepend_file`. This can be done by adding the following line into the `.htaccess` file of the web site on which the UI tests are performed:

```
php_value auto_prepend_file "/path/to/start-coverage.php"

```

After these steps are done, code coverage data will be dumped to the defined directory when the code coverage hint is detected.

An example can be observed in `examples/start-coverage.php`.

*Based on  Visit this page for more information.*

CoverageStarterIncluder
-----------------------

[](#coveragestarterincluder)

This class finds the PHP files that should be included in `.htaccess` by setting `auto_prepend_file`. A single value can be provided as the value of `auto_prepend_file`. In case that a project contains multiple sub-projects whose `start-coverage.php` should be included in the main `.htaccess` file, a PHP file that has `include` statements in it should be created to prepend multiple PHP files. This class handles this case.

The class searches for PHP files that should be included and includes them by keeping a reference to them. By this way, `__destruct` methods of the `CoverageHandler` instances created in `start-coverage.php` files are not called prematurely. They will be called when the script exits. Therefore, coverage data can be collected and dumped properly.

It is enough to create a PHP file, create an instance of `CoverageStarterIncluder` in it, and call `includeFiles()` to include all `start-coverage.php` files in the project. See `examples/coverage-starter-includer.php` and `examples/.htaccess` for an example.

ReportGenerator
---------------

[](#reportgenerator)

This class generates HTML and Clover reports from the coverage data dumped by `CoverageHandler`. To use this, create a file named as `generate-report.php` that creates an instance of `ReportGenerator` and calls `generate()` method. An example can be seen in `examples/generate-report.php`.

Next, to generate a report, just run the following command in the terminal

```
php /path/to/generate-report.php

```

After running this, the specified reports will be generated and saved into the specified directory.

To learn what parameters are provided in the constructor methods, simply refer to phpDoc.

PHPUnit Package
===============

[](#phpunit-package)

Contains the tools directly related to PHPUnit.

Redirect
--------

[](#redirect)

This class is responsible for redirecting a command that runs `phpunit` to correct PHPUnit runnable and modifying the command such that it contains the correct `phpunit.xml` file. This is done considering a case that there are unit and UI tests.

Consider the following case. There are two different tests, namely regular plugin tests and user interface tests. These tests require different versions of PHPUnit and different PHPUnit configurations. Selenium WebDriver supports PHPUnit 5.x, while WordPress supports PHPUnit 7.x. PHPStorm does not have an option to define different PHPUnit executables for different test directories. Yet, we want to use different PHPUnit versions.

This class looks for the path of the test files and redirects the command to the correct PHPUnit version by injecting the correct configuration file path. In short, this is just a wrapper that redirects PHPUnit commands to the correct PHPUnit executables.

### How to use this class

[](#how-to-use-this-class)

- Create a file named as `phpunit`
- Make sure this file's first line is `#!/usr/bin/env php`
- Make sure this file's *absolute* path is entered as the value of `Preferences > Languages & Frameworks > PHP > Test Frameworks > (select or create a test framework) > Path to phpunit.phar`.
- Make sure the value of `Preferences > Languages & Frameworks > PHP > Test Frameworks > (previously set framework) > Default configuration file` is the same as the value of `$configPathDefault` (i.e. absolute path of *`$relativeDefaultConfigXmlPath`*)
- Create an instance of this class in the created file and call `redirect()` method

After these are correctly set, you can use PHPStorm's buttons (run, debug, run with coverage) to run the tests.

An example `phpunit` file can be observed in `examples/phpunit`. Simply refer to the phpDoc to learn what the parameters are.

Development
===========

[](#development)

Testing UI coverage dumps and report generation
-----------------------------------------------

[](#testing-ui-coverage-dumps-and-report-generation)

First of all, make sure `127.0.0.1 phpunit-tools.test` line exists in `/etc/hosts` file. Also, a [`jwilder/nginx-proxy`](https://github.com/jwilder/nginx-proxy) should be up and running. Then, initialize the development environment by running

```
cd env && docker-compose up -d

```

Next, you can visit `phpunit-tools.test` in your browser. To produce coverage dumps, you can use `?coverageStartHintKey=` query, .e.g. `phpunit-tools.test?coverageStartHintKey=my-test`. After visiting this URL, the coverage dump file is created under `tests/site/coverages` directory. To produce a report, get into the container and run `site/files/generate-report.php`, e.g.

```
docker exec -it phpunit-tools-php bash
cd /var/www/html/files
php generate-report.php

```

After this is done, the reports can be found under `/var/www/html/files/reports` directory or `/path/to/phpunit-tools/tests/site/files/reports` directory. These are the same directories, since the local directory is attached as volume to the container.

Unit tests
----------

[](#unit-tests)

Unit tests are under `tests/Coverages` directory. The unit tests are incomplete.

TODO
----

[](#todo)

- Write tests to cover all of the functionality provided by the classes

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance53

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~122 days

Recently: every ~209 days

Total

8

Last Release

1625d ago

Major Versions

v1.0.0 → v2.0.02019-07-29

v2.2.0 → v3.0.02019-08-23

PHP version history (2 changes)v1.0.0PHP ~7.2

v3.0.2PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec951c537a6636e10f725285292b8a15a65c65d2fa88c5402dc3aebf3e32f34c?d=identicon)[turgutsaricam](/maintainers/turgutsaricam)

---

Top Contributors

[![turgutsaricam](https://avatars.githubusercontent.com/u/5666595?v=4)](https://github.com/turgutsaricam "turgutsaricam (28 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/turgutsaricam-phpunit-tools/health.svg)

```
[![Health](https://phpackages.com/badges/turgutsaricam-phpunit-tools/health.svg)](https://phpackages.com/packages/turgutsaricam-phpunit-tools)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[codeception/codeception

All-in-one PHP Testing Framework

4.9k86.2M2.9k](/packages/codeception-codeception)[phpunit/phpcov

CLI frontend for php-code-coverage

23621.1M583](/packages/phpunit-phpcov)[facile-it/paraunit

paraunit

146721.6k11](/packages/facile-it-paraunit)[matthiasnoback/live-code-coverage

Generate code coverage reports on a live server

1191.1M2](/packages/matthiasnoback-live-code-coverage)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
