Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

nette-tester

БесплатноБез исполняемых скриптовНе проверен

Use this skill whenever writing, modifying, or running .phpt test files with Nette Tester. Invoke for any task involving Tester\Assert methods (Assert::same…

netteот nette★ 47 звёзд на GitHub

Об этом скилле

Testing with Nette Tester

Nette Tester is a testing framework for PHP. Test files use the .phpt extension by convention; the runner also collects *Test.php.

Two failure modes worth knowing before writing a single test:

  • A test that executes no assertion is an error – Error: This test forgets to execute an assertion. (exit code 178). It is on by default via Environment::setup().
  • exit() / die() in a test ends it with code 0, i.e. as a PASS. Use Assert::fail() to fail deliberately.
composer require nette/tester --dev

Bootstrap File

The bootstrap file should set up the Tester environment and enable helper functions:

<?php declare(strict_types=1);

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

Tester\Environment::setup();
Tester\Environment::setupFunctions();  // enables test(), testException(), testNoError(), setUp()

Basic Test Structure

<?php declare(strict_types=1);

use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test('Calculator adds numbers correctly', function () {
	$calc = new App\Model\Calculator;
	Assert::same(5, $calc->add(2, 3));
});


test('Calculator throws on division by zero', function () {
	$calc = new App\Model\Calculator;
	Assert::exception(
		fn() => $calc->divide(10, 0),
		\DivisionByZeroError::class,
	);
});

Key points:

  • Use the test() function for each test case
  • The first parameter of test() should be a clear description of what is being tested
  • Do not add comments before test() calls - the description parameter serves this purpose
  • Group related tests in the same file
  • Test file naming: {ClassName}.phpt or {ClassName}.{feature}.phpt

Test Annotations

In the first docblock of the test file, before require. Case-insensitive; no effect when the file is run as plain php test.phpt. The first non-@ line is the test title (written TEST: ...).

Annotation Syntax Notes
@skip – always skipped
@phpVersion [op] version op: <= < == = != <> >= >, default >=
@phpExtension pdo, pdo_mysql comma/space separated; repeatable
@dataProvider file.ini[, query] path relative to the test file; a .php file returning array/Traversable works too
@dataProvider? ? file.ini leading ? = skip (not fail) when the file is missing
@multiple N runs the file exactly N times
@testCase – file holds a Tester\TestCase; runner runs each method in its own process
@exitCode N default 0
@outputMatch / @outputMatchFile pattern / file Assert::match / matchFile against stdout
@phpIni key=value same as the runner's -d key=value; repeatable

Trap — @phpVersion with an exact version. The skip condition is version_compare(annotation, actualPhpVersion, op), so equality skips. @phpVersion 8.4.3 on PHP 8.4.3 is skipped; write two components (@phpVersion 8.4), which sorts below 8.4.0 and therefore runs.

In the @dataProvider file form the test loads its own data set: $args = Tester\Environment::loadData(); — called once per run, returning one INI section. INI is parsed with INI_SCANNER_TYPED (values arrive typed). The optional query filters sections: its tokens are matched left to right against the whitespace-separated parts of the section name, operators <= =< < == = != <> >= => > (bare token = =), numeric tokens compared by version_compare. So @dataProvider databases.ini postgresql, >=9.0 selects [postgresql 9.1].

Tester\TestCase

class RectangleTest extends Tester\TestCase
{
	protected function setUp() {}      // before each test method
	protected function tearDown() {}   // after each test method
	public function testArea() { Assert::same(6, (new Rect(2, 3))->area()); }
}

(new RectangleTest)->run();   // MANDATORY, last line of the file
  • Discovery pattern is #^test[A-Z0-9_]#: testArea, test_area, test2 are tests — testarea silently is not.
  • A test* method must be public; a protected one is discovered, then fails with Method X is not public. Make it public or rename it.
  • Forgetting ->run(): with @testCase the runner reports Cannot list TestCase methods in file '…'. Do you call TestCase::run() in it?; without it the file merely defines a class and dies as This test forgets to execute an assertion. (exit 178).
  • Order per method: setUp(), test, tearDown(). If the test throws, tearDown() still runs but errors inside it are suppressed. A failure in setUp()/tearDown() fails the test.
  • In v2.6.1 run() aborts at the first failing method; @testCase sidesteps that by isolating each method.
  • $this->skip('reason') skips the current method from anywhere inside it.
/** @throws RuntimeException  Wrong argument order */   // class + optional message pattern; once per method
/** @dataProvider getArgs */      // value without a dot -> method of this class
/** @d
Полный SKILL.md на GitHub

Установить nette-tester в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл nette-tester?

Use this skill whenever writing, modifying, or running .phpt test files with Nette Tester. Invoke for any task involving Tester\Assert methods (Assert::same, Assert::match, Assert::exception, etc.), test bootstrap setup, vendor/bin/tester commands, or debugging failing test output (.expected/.actual files). Also use when the user needs to write tests for a Nette project and asks about test structure, the test() function, testException(), or assertion methods. This skill is specifically for Nette Tester – do not use for PHPUnit, Pest, Jest, Vitest, or other testing frameworks, and do not use for general PHP testing without Nette context.

Как установить скилл nette-tester?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл nette-tester запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить nette-tester с