nette/tester
Nette Tester is a lightweight PHP unit testing framework focused on fast execution and readable assertions. It supports test cases, data providers, output capture, and isolation of tests, making it easy to write reliable automated tests without heavy setup.
Start by installing nette/tester via Composer: composer require --dev nette/tester. Create a tests directory and write your first test as a PHP file ending in Test.php (e.g., tests/ExampleTest.php). Within, define test cases using the test() global function (enabled by including the autoloader and calling Environment::setupFunctions() or relying on auto-bootstrapping):
<?php
require __DIR__ . '/vendor/autoload.php';
use Nette\Tester\Assert;
test('addition works', function () {
Assert::same(2 + 2, 4);
});
Run all tests with vendor/bin/tester tests. For rapid feedback, use --watch mode (vendor/bin/tester --watch tests) to rerun affected tests on file changes.
test() for simple functional tests and TestCase classes for stateful, lifecycle-aware tests (e.g., when needing setUp(), tearDown(), or data providers).@dataProvider annotation or pass an array to test('name', callback, $data) to DRY repeated assertions.DomQuery toassert on HTML output—ideal for testing rendered views or HTTP responses:
$html = '<div><p>Hello</p></div>';
$q = new DomQuery($html);
Assert::equal('Hello', $q->find('p')->text());
-j N (e.g., -j 4) for speed—now fully supported on Windows since v2.6.0.vendor/bin/tester --coverage src --coverage-src src tests to generate HTML/Clover coverage reports—works with PCOV (preferred) and Xdebug.Runner::addAsyncTest() or run CLI scripts with PhpInterpreter for isolated process testing.php.ini by default: Since v2.6.0, Tester respects your system php.ini—disable with --no-ini or Environment::setupFunctions(['phpIni' => false]) if relying on dev-only settings.tearDown() runs on failure: Finally fixed in v2.6.0—verify cleanup logic actually runs even when tests throw; avoid assumptions about order without explicit setup.test() vs TestCase: test() functions do not support data providers—use TestCase::data() or the newer test('name', callback, $data) form for parametrized tests.--watch uses filemtime, so don’t manually touch files. Silent errors during reload can be debugged with -v.FileMock pitfalls: Always call FileMock::cleanup() in tearDown() when using FileMock to avoid stray temp files across runs.Dumper::dump() for debugging—not var_dump()—it’s PHPUnit/Xdebug-friendly, supports color, and handles recursions gracefully. In PhpStorm, install Awesome Console for clickable stack trace links.How can I help you explore Laravel packages today?