Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Tester Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Functional & Unit Tests Together: Use test() for simple functional tests and TestCase classes for stateful, lifecycle-aware tests (e.g., when needing setUp(), tearDown(), or data providers).
  • Data Providers: Use @dataProvider annotation or pass an array to test('name', callback, $data) to DRY repeated assertions.
  • HTML DOM Assertions: Use 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());
    
  • Parallel Testing: Enable parallel execution with -j N (e.g., -j 4) for speed—now fully supported on Windows since v2.6.0.
  • Code Coverage: Run vendor/bin/tester --coverage src --coverage-src src tests to generate HTML/Clover coverage reports—works with PCOV (preferred) and Xdebug.
  • Async & CLI Testing: Use Runner::addAsyncTest() or run CLI scripts with PhpInterpreter for isolated process testing.

Gotchas and Tips

  • System 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 mode quirks: Paths must be absolute; --watch uses filemtime, so don’t manually touch files. Silent errors during reload can be debugged with -v.
  • Coverage: PCOV > Xdebug: Prefer PCOV—it's faster, works out-of-the-box with Tester, and integrates cleanly with CI. Disable Xdebug’s collect_includes.
  • FileMock pitfalls: Always call FileMock::cleanup() in tearDown() when using FileMock to avoid stray temp files across runs.
  • Console output: Use 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport