PHPackages                             nette/tester - 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. nette/tester

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

nette/tester
============

Nette Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏

v2.6.0(3mo ago)4917.3M↓25.1%73[3 issues](https://github.com/nette/tester/issues)[10 PRs](https://github.com/nette/tester/pulls)20BSD-3-ClausePHPPHP 8.0 - 8.5CI failing

Since Nov 15Pushed 2mo ago36 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (45)Used By (20)

[![Nette Tester](https://private-user-images.githubusercontent.com/194960/331242065-19423421-c7e9-4bcb-a8cc-167003de2c70.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNDE4ODUsIm5iZiI6MTc3NDM0MTU4NSwicGF0aCI6Ii8xOTQ5NjAvMzMxMjQyMDY1LTE5NDIzNDIxLWM3ZTktNGJjYi1hOGNjLTE2NzAwM2RlMmM3MC5qcGc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMyNFQwODM5NDVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zNTFmZjUxNDg1NDI2ZWMyMmFmZjFmYzZhN2NhOTFmYWViMDliNGNhYmM3NmMwOWRlNzA4MzFhYWM1Y2I5MTgyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.hjEeGRcedRk-oNmesHndKH9W8mm6ylKT5Wr2yBD_AOE)](https://tester.nette.org)

[![Downloads this Month](https://camo.githubusercontent.com/a6ba84b1fb49dbc7981c9867ab32282ba73ee626895f111a148308bfc83767ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e657474652f7465737465722e737667)](https://packagist.org/packages/nette/tester)[![Tests](https://github.com/nette/tester/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/tester/actions)[![Latest Stable Version](https://camo.githubusercontent.com/49b92d27c4971d0549c2b48d18b656ccc83afca0369e41edc6160d19b40eb3f2/68747470733a2f2f706f7365722e707567782e6f72672f6e657474652f7465737465722f762f737461626c65)](https://github.com/nette/tester/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/nette/tester/blob/master/license.md)

Introduction
------------

[](#introduction)

Nette Tester is a productive and enjoyable unit testing framework. It's used by the [Nette Framework](https://nette.org) and is capable of testing any PHP code.

Documentation is available on the [Nette Tester website](https://tester.nette.org). Read the [blog](https://blog.nette.org/category/tester/) for new information.

[Support Tester](https://github.com/sponsors/dg)
------------------------------------------------

[](#support-tester)

Do you like Nette Tester? Are you looking forward to the new features?

[![Buy me a coffee](https://camo.githubusercontent.com/afa7c20ccaac10ac4f1f51669bafb212856b932e0c8b276cb290336cf08624b8/68747470733a2f2f66696c65732e6e657474652e6f72672f69636f6e732f646f6e6174696f6e2d332e737667)](https://github.com/sponsors/dg)

Thank you!

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

[](#installation)

The recommended way to install Nette Tester is through Composer:

```
composer require nette/tester --dev

```

Alternatively, you can download the [tester.phar](https://github.com/nette/tester/releases) file.

Nette Tester 2.6 is compatible with PHP 8.0 to 8.5. Collecting and processing code coverage information depends on Xdebug or PCOV extension, or PHPDBG SAPI.

Writing Tests
-------------

[](#writing-tests)

Imagine that we are testing this simple class:

```
class Greeting
{
	function say($name)
	{
		if (!$name) {
			throw new InvalidArgumentException('Invalid name.');
		}
		return "Hello $name";
	}
}
```

So we create test file named `greeting.test.phpt`:

```
require 'src/bootstrap.php';

use Tester\Assert;

$h = new Greeting;

// use an assertion function to test say()
Assert::same('Hello John', $h->say('John'));
```

Thats' all!

Now we run tests from command-line using the `tester` command:

```
> tester
 _____ ___  ___ _____ ___  ___
|_   _/ __)( __/_   _/ __)| _ )
  |_| \___ /___) |_| \___ |_|_\  v2.6

PHP 8.2.0 | php | 8 threads
.
OK (1 tests, 0 skipped, 0.0 seconds)

```

Nette Tester prints dot for successful test, F for failed test and S when the test has been skipped.

Assertions
----------

[](#assertions)

This table shows all assertions (class `Assert` means `Tester\Assert`):

- `Assert::same($expected, $actual)` - Reports an error if $expected and $actual are not the same.
- `Assert::notSame($expected, $actual)` - Reports an error if $expected and $actual are the same.
- `Assert::equal($expected, $actual)` - Like same(), but identity of objects and the order of keys in the arrays are ignored.
- `Assert::notEqual($expected, $actual)` - Like notSame(), but identity of objects and arrays order are ignored.
- `Assert::contains($needle, array $haystack)` - Reports an error if $needle is not an element of $haystack.
- `Assert::contains($needle, string $haystack)` - Reports an error if $needle is not a substring of $haystack.
- `Assert::notContains($needle, array $haystack)` - Reports an error if $needle is an element of $haystack.
- `Assert::notContains($needle, string $haystack)` - Reports an error if $needle is a substring of $haystack.
- `Assert::true($value)` - Reports an error if $value is not true.
- `Assert::false($value)` - Reports an error if $value is not false.
- `Assert::truthy($value)` - Reports an error if $value is not truthy.
- `Assert::falsey($value)` - Reports an error if $value is not falsey.
- `Assert::null($value)` - Reports an error if $value is not null.
- `Assert::nan($value)` - Reports an error if $value is not NAN.
- `Assert::type($type, $value)` - Reports an error if the variable $value is not of PHP or class type $type.
- `Assert::exception($closure, $class, $message = null, $code = null)` - Checks if the function throws exception.
- `Assert::error($closure, $level, $message = null)` - Checks if the function $closure throws PHP warning/notice/error.
- `Assert::noError($closure)` - Checks that the function $closure does not throw PHP warning/notice/error or exception.
- `Assert::match($pattern, $value)` - Compares result using regular expression or mask.
- `Assert::matchFile($file, $value)` - Compares result using regular expression or mask sorted in file.
- `Assert::count($count, $value)` - Reports an error if number of items in $value is not $count.
- `Assert::with($objectOrClass, $closure)` - Executes function that can access private and protected members of given object via $this.

Testing exceptions:

```
Assert::exception(function () {
	$h = new Greeting;
	$h->say(null);
}, InvalidArgumentException::class, 'Invalid name.');
```

Testing PHP errors, warnings or notices:

```
Assert::error(function () {
	$h = new Greeting;
	echo $h->abc;
}, E_NOTICE, 'Undefined property: Greeting::$abc');
```

Testing private access methods:

```
$h = new Greeting;
Assert::with($h, function () {
	// normalize() is internal private method.
	Assert::same('Hello David', $this->normalize('Hello david')); // $this is Greeting
});
```

Tips and features
-----------------

[](#tips-and-features)

Running unit tests manually is annoying, so let Nette Tester to watch your folder with code and automatically re-run tests whenever code is changed:

```
tester -w /my/source/codes

```

Running tests in parallel is very much faster and Nette Tester uses 8 threads as default. If you wish to run the tests in series use:

```
tester -j 1

```

How do you find code that is not yet tested? Use Code-Coverage Analysis. This feature requires you have installed [Xdebug](https://xdebug.org/) or [PCOV](https://github.com/krakjoe/pcov)extension, or you are using PHPDBG SAPI. This will generate nice HTML report in `coverage.html`.

```
tester . -c php.ini --coverage coverage.html --coverage-src /my/source/codes

```

We can load Nette Tester using Composer's autoloader. In this case it is important to setup Nette Tester environment:

```
require 'vendor/autoload.php';

Tester\Environment::setup();
```

We can also test HTML pages. Let the [template engine](https://latte.nette.org) generate HTML code or download existing page to `$html` variable. We will check whether the page contains form fields for username and password. The syntax is the same as the CSS selectors:

```
$dom = Tester\DomQuery::fromHtml($html);

Assert::true($dom->has('input[name="username"]'));
Assert::true($dom->has('input[name="password"]'));
```

For more inspiration see how [Nette Tester tests itself](https://github.com/nette/tester/tree/master/tests).

Running tests
-------------

[](#running-tests)

The command-line test runner can be invoked through the `tester` command (or `php tester.php`). Take a look at the command-line options:

```
> tester

Usage:
    tester [options] [ | ]...

Options:
    -p                     Specify PHP interpreter to run (default: php).
    -c                     Use custom php.ini, ignore system configuration.
    -C                           With -c, include system configuration as well.
    -l | --log             Write log to file .
    -d ...            Define INI entry 'key' with value 'val'.
    -s                           Show information about skipped tests.
    --stop-on-fail               Stop execution upon the first failure.
    -j                      Run  jobs in parallel (default: 8).
    -o
                                 Specify output format.
    -w | --watch           Watch directory.
    -i | --info                  Show tests environment info and exit.
    --setup                Script for runner setup.
    --temp                 Path to temporary directory. Default by sys_get_temp_dir().
    --colors [1|0]               Enable or disable colors.
    --coverage             Generate code coverage report to file.
    --coverage-src         Path to source code.
    -h | --help                  This help.

```

###  Health Score

77

—

ExcellentBetter than 100% of packages

Maintenance82

Actively maintained with recent releases

Popularity66

Solid adoption and visibility

Community58

Growing community involvement

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 67.7% 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 ~112 days

Total

44

Last Release

116d ago

Major Versions

v0.9.5 → v1.0.02014-02-08

v1.7.1 → v2.0.02017-08-22

v1.x-dev → v2.0.22018-06-07

PHP version history (11 changes)v0.9.0PHP &gt;=5.3.0

v2.0.0PHP &gt;=5.6.0

v2.1.0PHP &gt;=7.1

v2.4.0PHP &gt;=7.2 &lt;8.1

v2.4.1PHP &gt;=7.2 &lt;8.2

v2.4.3PHP &gt;=7.2 &lt;8.3

v2.5.0PHP &gt;=8.0 &lt;8.3

v2.5.1PHP &gt;=8.0 &lt;8.4

v2.5.3PHP 8.0 - 8.3

v2.5.4PHP 8.0 - 8.4

v2.5.6PHP 8.0 - 8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f266513a3ca97500ec3d85d562b9279c7a6346358fe2b8d90390ece717a027?d=identicon)[david@grudl.com](/maintainers/david@grudl.com)

---

Top Contributors

[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (686 commits)")[![milo](https://avatars.githubusercontent.com/u/439140?v=4)](https://github.com/milo "milo (227 commits)")[![JanTvrdik](https://avatars.githubusercontent.com/u/175109?v=4)](https://github.com/JanTvrdik "JanTvrdik (18 commits)")[![kravco](https://avatars.githubusercontent.com/u/115938?v=4)](https://github.com/kravco "kravco (17 commits)")[![Vrtak-CZ](https://avatars.githubusercontent.com/u/112567?v=4)](https://github.com/Vrtak-CZ "Vrtak-CZ (10 commits)")[![vrana](https://avatars.githubusercontent.com/u/117453?v=4)](https://github.com/vrana "vrana (7 commits)")[![fprochazka](https://avatars.githubusercontent.com/u/158625?v=4)](https://github.com/fprochazka "fprochazka (6 commits)")[![jiripudil](https://avatars.githubusercontent.com/u/1042159?v=4)](https://github.com/jiripudil "jiripudil (5 commits)")[![vojtech-dobes](https://avatars.githubusercontent.com/u/415925?v=4)](https://github.com/vojtech-dobes "vojtech-dobes (5 commits)")[![MartinMystikJonas](https://avatars.githubusercontent.com/u/2094752?v=4)](https://github.com/MartinMystikJonas "MartinMystikJonas (4 commits)")[![juzna](https://avatars.githubusercontent.com/u/227416?v=4)](https://github.com/juzna "juzna (4 commits)")[![Majkl578](https://avatars.githubusercontent.com/u/144181?v=4)](https://github.com/Majkl578 "Majkl578 (4 commits)")[![smuuf](https://avatars.githubusercontent.com/u/6860713?v=4)](https://github.com/smuuf "smuuf (2 commits)")[![janbarasek](https://avatars.githubusercontent.com/u/4738758?v=4)](https://github.com/janbarasek "janbarasek (2 commits)")[![stekycz](https://avatars.githubusercontent.com/u/865447?v=4)](https://github.com/stekycz "stekycz (2 commits)")[![xpavp03](https://avatars.githubusercontent.com/u/853656?v=4)](https://github.com/xpavp03 "xpavp03 (1 commits)")[![besanek](https://avatars.githubusercontent.com/u/3389310?v=4)](https://github.com/besanek "besanek (1 commits)")[![Beutlin](https://avatars.githubusercontent.com/u/1647207?v=4)](https://github.com/Beutlin "Beutlin (1 commits)")[![diegosardina](https://avatars.githubusercontent.com/u/22911186?v=4)](https://github.com/diegosardina "diegosardina (1 commits)")[![grogy](https://avatars.githubusercontent.com/u/1322983?v=4)](https://github.com/grogy "grogy (1 commits)")

---

Tags

assertionscode-coveragenettenette-frameworkpcovphpphpdbgphpunittesterunit-testingxdebugtestingphpunitunitnetteassertionsXdebugclovercode coveragephpdbgpcov

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nette-tester/health.svg)

```
[![Health](https://phpackages.com/badges/nette-tester/health.svg)](https://phpackages.com/packages/nette-tester)
```

###  Alternatives

[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)[rregeer/phpunit-coverage-check

Check the code coverage using the clover report of phpunit

606.1M179](/packages/rregeer-phpunit-coverage-check)[tcz/phpunit-mockfunction

PHPUnit extension that uses runkit to mock PHP functions (both user-defined and system)

4950.3k2](/packages/tcz-phpunit-mockfunction)[shipmonk/coverage-guard

Enforce code coverage in your CI. Not by percentage, but target core methods. No more untested Facades, Controllers, or Repositories. Allows you to start enforcing coverage for new code only!

5318.5k4](/packages/shipmonk-coverage-guard)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

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