PHPackages                             petrkotek/phpunit-naughtytestdetector - 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. petrkotek/phpunit-naughtytestdetector

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

petrkotek/phpunit-naughtytestdetector
=====================================

"Naughty test detector" for PHPUnit. Identifies tests, which don't clean after themselves.

v3.0.0(4y ago)3790.8k↓32.9%3[2 issues](https://github.com/petrkotek/phpunit-naughtytestdetector/issues)Apache License 2.0PHPPHP &gt;=7.2

Since Oct 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/petrkotek/phpunit-naughtytestdetector)[ Packagist](https://packagist.org/packages/petrkotek/phpunit-naughtytestdetector)[ RSS](/packages/petrkotek-phpunit-naughtytestdetector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (15)Used By (0)

phpunit-naughtytestdetector
===========================

[](#phpunit-naughtytestdetector)

[![Build Status](https://camo.githubusercontent.com/b3285994dbc2b2f5f47cf9414e75a9fffa2dec9be436a13ec9f2cf9a18124acf/68747470733a2f2f7472617669732d63692e6f72672f706574726b6f74656b2f706870756e69742d6e617567687479746573746465746563746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/petrkotek/phpunit-naughtytestdetector)[![Coverage Status](https://camo.githubusercontent.com/17d62ce3e73cbe187a276026d63c8b9f41ae05da0da02a259326e9b8f6d154fd/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f706574726b6f74656b2f706870756e69742d6e617567687479746573746465746563746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/petrkotek/phpunit-naughtytestdetector?branch=master)

"Naughty test detector" for PHPUnit. Identifies tests leaving garbage after themselves.

Many of us have been there - your integration test works in isolation, but breaks when running in a sequence of tests. This can be very difficult to troubleshoot, but luckily `phpunit-naughtytestdetector` is here to help.

Requirements
------------

[](#requirements)

- PHPUnit 6.0+
- Supported PHP versions: 7.0 and 7.1

Note: for older PHPUnit or PHP 5.6, use `v0.2.0`.

Installation
------------

[](#installation)

NaughtyTestDetector is installable via [Composer](http://getcomposer.org) and should be added as a `require-dev` dependency:

```
composer require --dev petrkotek/phpunit-naughtytestdetector

```

Usage
-----

[](#usage)

#### 1. Enable `NaughtyTestListener` by adding the following to your test suite's `phpunit.xml` file:

[](#1-enable-naughtytestlistener-by-adding-the-following-to-your-test-suites-phpunitxml-file)

```

    ...

                MyProject\TestUtils\MyMetricFetcher

                        hello world

                        false

                        true

                        false

```

#### 2. Implement the `MetricFetcher` interface, e.g.:

[](#2-implement-the-metricfetcher-interface-eg)

```
namespace MyProject\TestUtils\MyMetricFetcher;

use PetrKotek\NaughtyTestDetector\MetricFetcher;

class MyMetricFetcher implements MetricFetcher
{
    private $db;

    public function __construct()
    {
        $this->db = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
    }

    /**
     * @return array
     */
    public function fetchMetrics()
    {
        $result = mysqli_query($this->db, 'SELECT COUNT * FROM my_table');
        $row = mysqli_fetch_row($result);

        return ['records' => $row[0];
    }
}
```

Tip: You can also use built-in metric fetcher, e.g. `PetrKotek\NaughtyTestDetector\MetricFetchers\GlobalsMetricFetcher`.

#### 3. Run your test suite.

[](#3-run-your-test-suite)

E.g. `phpunit --configuration integration.xml`

`NaughtyTestListener` will fetch metrics before &amp; after each TestSuite (aka "test class") and if there is a difference between before &amp; after, it prints out like message like this:

```
MyProject\Integration\MyNamespace\BadTest is naughty!
 - my_table: 0 -> 5 (+5)

```

This means, that before the test, there was `0` records in the `my_table` and after executing all the tests, there were `5` records.

Note: If you want to temporarily disable Naughty Test Detector, use `DISABLE_NAUGHTY_TEST_DETECTOR` enviromental variable, e.g. `DISABLE_NAUGHTY_TEST_DETECTOR=1 phpunit --configuration integration.xml`.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance7

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% 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 ~161 days

Recently: every ~370 days

Total

12

Last Release

1730d ago

Major Versions

v0.2.0 → v1.0.02017-06-08

v1.1.0 → v2.0.02019-04-30

v2.0.1 → v3.0.02021-08-22

PHP version history (3 changes)v0.1.0PHP ~5.3 || ^7.0

v2.0.0PHP ^7.1

v3.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5679032?v=4)[Petr Kotek](/maintainers/petrkotek)[@petrkotek](https://github.com/petrkotek)

---

Top Contributors

[![petrkotek](https://avatars.githubusercontent.com/u/5679032?v=4)](https://github.com/petrkotek "petrkotek (34 commits)")[![repzy](https://avatars.githubusercontent.com/u/8057340?v=4)](https://github.com/repzy "repzy (1 commits)")

---

Tags

listenerphpphpunittestingphpunitdetectorcleanupcleaningflakymessynaughtyerratic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/petrkotek-phpunit-naughtytestdetector/health.svg)

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

###  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)[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78337.2M122](/packages/johnkary-phpunit-speedtrap)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

57026.3M456](/packages/dg-bypass-finals)

PHPackages © 2026

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