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

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

webino/nette-tester
===================

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

v2.3.0(6y ago)11041BSD-3-ClausePHPPHP &gt;=7.1

Since Nov 15Pushed 2y agoCompare

[ Source](https://github.com/webino/nette-tester)[ Packagist](https://packagist.org/packages/webino/nette-tester)[ Docs](https://tester.nette.org)[ RSS](/packages/webino-nette-tester/feed)WikiDiscussions support/1.7 Synced 3d ago

READMEChangelogDependenciesVersions (32)Used By (1)

[Nette Tester](https://tester.nette.org): enjoyable unit testing
================================================================

[](#nette-tester-enjoyable-unit-testing)

[![Downloads this Month](https://camo.githubusercontent.com/a6ba84b1fb49dbc7981c9867ab32282ba73ee626895f111a148308bfc83767ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e657474652f7465737465722e737667)](https://packagist.org/packages/nette/tester)[![Build Status](https://camo.githubusercontent.com/bea2f827b29f2f48b6fd0f9519defb1d29c709ea8ae3cc7ee9ccccc7e22255cc/68747470733a2f2f7472617669732d63692e6f72672f6e657474652f7465737465722e7376673f6272616e63683d76312e78)](https://travis-ci.org/nette/tester)[![Build Status Windows](https://camo.githubusercontent.com/568a74156772408585b9e2d4b058a65530ebc22daa750b6db5c91908824aa3e5/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f6769746875622f6e657474652f7465737465723f6272616e63683d76312e78267376673d74727565)](https://ci.appveyor.com/project/dg/tester/branch/v1.x)[![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/v1.x/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.

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 requires PHP 5.3.0 and supports PHP up to 7.2. Collecting and processing code coverage information depends on Xdebug, or PHPDBG.

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
 _____ ___  ___ _____ ___  ___
|_   _/ __)( __/_   _/ __)| _ )
  |_| \___ /___) |_| \___ |_|_\  v1.7.2

PHP 5.3.16 | "php-cgi" -n | 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.

Testing exceptions:

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

Testing PHP errors, warnings or notices:

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

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](http://xdebug.org/) in `php.ini`. 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/v1.x/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.php [options] [ | ]...

Options:
    -p                     Specify PHP executable to run (default: php-cgi).
    -c                     Look for php.ini file (or look in directory) .
    -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.
    --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

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 67.2% 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 ~153 days

Recently: every ~492 days

Total

27

Last Release

930d ago

Major Versions

v0.9.5 → v1.0.02014-02-08

v1.7.1 → v2.0.02017-08-22

v1.7.2 → v2.0.22018-06-07

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

v2.0.0PHP &gt;=5.6.0

v2.1.0PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (441 commits)")[![milo](https://avatars.githubusercontent.com/u/439140?v=4)](https://github.com/milo "milo (134 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)")[![JanTvrdik](https://avatars.githubusercontent.com/u/175109?v=4)](https://github.com/JanTvrdik "JanTvrdik (7 commits)")[![fprochazka](https://avatars.githubusercontent.com/u/158625?v=4)](https://github.com/fprochazka "fprochazka (6 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)")[![vojtech-dobes](https://avatars.githubusercontent.com/u/415925?v=4)](https://github.com/vojtech-dobes "vojtech-dobes (3 commits)")[![bacinsky](https://avatars.githubusercontent.com/u/3078875?v=4)](https://github.com/bacinsky "bacinsky (3 commits)")[![MartinMystikJonas](https://avatars.githubusercontent.com/u/2094752?v=4)](https://github.com/MartinMystikJonas "MartinMystikJonas (3 commits)")[![stekycz](https://avatars.githubusercontent.com/u/865447?v=4)](https://github.com/stekycz "stekycz (2 commits)")[![xmedeko](https://avatars.githubusercontent.com/u/1101801?v=4)](https://github.com/xmedeko "xmedeko (1 commits)")[![1josefnevoral](https://avatars.githubusercontent.com/u/1532335?v=4)](https://github.com/1josefnevoral "1josefnevoral (1 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)")[![danielkurecka](https://avatars.githubusercontent.com/u/1924013?v=4)](https://github.com/danielkurecka "danielkurecka (1 commits)")[![forrest79](https://avatars.githubusercontent.com/u/160766?v=4)](https://github.com/forrest79 "forrest79 (1 commits)")[![janmarek](https://avatars.githubusercontent.com/u/150257?v=4)](https://github.com/janmarek "janmarek (1 commits)")

---

Tags

libraryltsnettetestertestingphpunitunitnetteassertionsXdebugclovercode coveragephpdbgpcov

### Embed Badge

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

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

###  Alternatives

[nette/tester

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

4917.3M1.5k](/packages/nette-tester)[dg/bypass-finals

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

56426.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)
