PHPackages                             tomkyle/find-run-test - 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. tomkyle/find-run-test

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

tomkyle/find-run-test
=====================

Find and run the PHPUnit test for a single changed PHP class file, most useful when watching the filesystem

1.2.0(3mo ago)02.0k9MITPHPPHP ^8.4CI passing

Since Aug 10Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/tomkyle/find-run-test)[ Packagist](https://packagist.org/packages/tomkyle/find-run-test)[ RSS](/packages/tomkyle-find-run-test/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (15)Used By (9)

FRT · Find and Run Test
=======================

[](#frt--find-and-run-test)

[![Composer Version](https://camo.githubusercontent.com/2dbeb7f40e61436c4f001baa6621742d5a7a6b87852b9ff48c68ef8f5dc34e8c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d6b796c652f66696e642d72756e2d74657374)](https://packagist.org/packages/tomkyle/find-run-test)[![PHP version](https://camo.githubusercontent.com/07e3f9c4045f1b46278a2242b79bbd8a9a1a8f0d11dad2aec1d871415c408452/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6d6b796c652f66696e642d72756e2d74657374)](https://packagist.org/packages/tomkyle/find-run-test)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/c9a22320668f177524fb97d94fe8acbd87ede2c6bf4f2d60633f9bb16b061e6e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6d6b796c652f66696e642d72756e2d746573742f7068702e796d6c)](https://github.com/tomkyle/find-run-test/actions/workflows/php.yml)[![Packagist License](https://camo.githubusercontent.com/25965420086ee899338c8243f65a725f4fe5ec800d1bb804d89073c5465ad734/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6d6b796c652f66696e642d72756e2d74657374)](LICENSE.txt)

About
-----

[](#about)

**FRT automatically executes the associated PHPUnit test for a changed source code file.**

**Comparison with spatie/phpunit-watcher:** [spatie/phpunit-watcher](https://packagist.org/packages/spatie/phpunit-watcher) re-executes the *entire* PHPUnit test suite once a source code file has changed. The executed tests can be restricted to *specific* tests using the `--filter` option. This means that regardless of which file is changed or saved, only the specified unit tests are executed.

```
$ vendor/bin/phpunit-watcher watch
$ vendor/bin/phpunit-watcher watch --filter=certain_test
```

**tomkyle/find-run-test takes a different approach:** After saving a file, only the PHPUnit test associated with the modified file is executed.

COMPARISONtomkyle/frtspatie/phpunit-watcherWatch processvia *chokidar* in package.json*phpunit-watcher* commandConfigurationCLI optionsConfig file and CLI optionsCustomizationbasicbetterChaining with phpstan, phpcs or rectorvia built-in shell `&&` operatorsnoneOpen shells neededOneTwoTests runThose associated with changed file*All* or *all specified* testsInstallation
------------

[](#installation)

Install FRT with Composer:

```
$ composer require --dev tomkyle/find-run-test
```

How it works
------------

[](#how-it-works)

The `vendor/bin/frt` executable expects the PHP file of which the source code has changed as argument. It will then look for any PHPUnit test file which suits the class name of the changed file and run the associated test. For example:

1. You update file `src/MyClass.php` and pass that file as argument to FRT.

    ```
    $ vendor/bin/frt src/MyClass.php
    ```
2. FRT will look for matching PHPUnit tests inside the project’s `tests` directory.
3. If there is a test file `MyClassTest.php`, FRT will hand it over to PHPUnit, like so:

    ```
    $ vendor/bin/phpunit --filter=MyClassTest.php
    ```

Automation
----------

[](#automation)

Our goal is to automate testing as much as possible, and so do we with running unit tests. In the Node-based app developing world, [Chokidar](https://www.npmjs.com/package/chokidar) is one of the go-to file watching libraries, most often used for frontend building with *webpack, gulp, workbox,* and such. We will utilize it for FRT.

Install *Chokidar* with NPM:

```
$ npm install --dev chokidar-cli
```

Create a `watch` task inside the project root’s **package.json**, for example:

```
{
  "name": "my-app",
  "devDependencies": {
    "chokidar-cli": "^3.0.0"
  },
  "scripts": {
    "watch": "chokidar \"src/**/*.php\" -c \"./vendor/bin/frt {path}\"",
  }
}
```

Back to our project root: Start the watch process with `npm run watch`. Chokidar will now report any PHP source code change and hand over the changed file to FRT, which in turn will call PHPUnit:

```
$ npm run watch
# Output will be like ...

Watching "src/**/*.php" ..
```

Assuming we just edited `src/SomeNamespace/MyClass.php`, we get this:

```
change:src/SomeNamespace/MyClass.php
PHPUnit 11.3.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.10
Configuration: /Users/john_doe/vendor-project/phpunit.dist.xml

....  4 / 4 (100%)

Time: 00:00.016, Memory: 10.00 MB

My Class (tests\Unit\MyClassTest)
 ✔ Construct
 ✔ Get styles
 ✔ Get colors
 ✔ Get throws exception for invalid color

OK (4 tests, 5 assertions)

```

In case no associated PHPUnit test can be found, FRT will report this:

```
No test available: src/SomeInterface.php

```

Chain with other test tools
---------------------------

[](#chain-with-other-test-tools)

Install the PHP development tools using Composer:

```
$ composer require --dev phpstan/phpstan
$ composer require --dev rector/rector
$ compsoer require --dev friendsofphp/php-cs-fixer
# If not already
$ composer require --dev phpunit/phpunit
```

Add the PHP tools as NPM scripts to package.json – see the full example in [examples/package.json](./examples/package.json)

```
{
  "name": "my-app",
  "devDependencies": {
    "chokidar-cli": "^3.0.0",
    "npm-run-all": "^4.1.5"
  },
  "scripts": {

    "watch": "npm-run-all -p watch:*",
    "watch:src": "chokidar \"src/**/*.php\" -c \"./vendor/bin/frt {path} && npm run phpstan {path} && npm run rector {path}\"",
    "watch:tests": "chokidar \"tests/**/*.php\" -c \"npm run phpunit:short {path}\"",

    "phpstan": "./vendor/bin/phpstan --no-progress analyse",

    "phpcs": "npm run phpcs:apply -- --dry-run",
    "phpcs:apply": "./vendor/bin/php-cs-fixer fix --verbose --diff",

    "rector": "npm run rector:apply -- --dry-run",
    "rector:apply": "./vendor/bin/rector process",

    "phpunit": "./vendor/bin/phpunit --testdox",
    "phpunit:short": "npm run phpunit -- --no-coverage"
  }
}
```

Start watching:

```
$ npm run watch
# Output will be like ...

Watching "src/**/*.php" ..
```

Development
-----------

[](#development)

### Clone repo and install requirements

[](#clone-repo-and-install-requirements)

```
$ git clone git@github.com:tomkyle/frt.git
$ composer install
$ pnpm install
```

### Watch source and run various tests

[](#watch-source-and-run-various-tests)

This will watch changes inside the **src/** and **tests/** directories and run a series of tests:

1. Find and run the according unit test with *PHPUnit*.
2. Find possible bugs and documentation isses using *phpstan*.
3. Analyse code style and give hints on newer syntax using *Rector*.

```
$ npm run watch
```

### Run all tests

[](#run-all-tests)

```
$ npm run phpunit
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance81

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

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 ~45 days

Recently: every ~56 days

Total

13

Last Release

100d ago

PHP version history (3 changes)1.0.0PHP ^8.2

1.1.0PHP ^8.3

1.2.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/412560?v=4)[Carsten Witt](/maintainers/tomkyle)[@tomkyle](https://github.com/tomkyle)

---

Top Contributors

[![tomkyle](https://avatars.githubusercontent.com/u/412560?v=4)](https://github.com/tomkyle "tomkyle (66 commits)")

---

Tags

phpphp-testingphpunitunit-testingunit-testsphpunitfilesystemunit testingwatchertest runner

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomkyle-find-run-test/health.svg)

```
[![Health](https://phpackages.com/badges/tomkyle-find-run-test/health.svg)](https://phpackages.com/packages/tomkyle-find-run-test)
```

###  Alternatives

[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k26.2M1.8k](/packages/infection-infection)[codeception/codeception

All-in-one PHP Testing Framework

4.9k86.2M2.9k](/packages/codeception-codeception)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[kenjis/ci-phpunit-test

An easier way to use PHPUnit with CodeIgniter 3.x

5861.2M3](/packages/kenjis-ci-phpunit-test)[gecko-packages/gecko-php-unit

Additional PHPUnit asserts and constraints.

1373.9M4](/packages/gecko-packages-gecko-php-unit)[donatj/mock-webserver

Simple mock web server for unit testing

1382.5M80](/packages/donatj-mock-webserver)

PHPackages © 2026

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