Skip to content
...

All Attributes ​

Testo uses PHP attributes to configure tests, lifecycle hooks, data providers, and more. This page lists all available attributes grouped by plugin. Click any attribute name for full documentation with parameters and examples.

AttributePluginDescription
#[AfterClass]#[AfterClass(int $priority = 0)]Runs a method once after all tests in the class. Suitable for cleanup.LifecycleRuns a method once after all tests in the class. Suitable for cleanup.
#[AfterTest]#[AfterTest(int $priority = 0)]Runs a method after each test in the class.LifecycleRuns a method after each test in the class.
#[BeforeClass]#[BeforeClass(int $priority = 0)]Runs a method once before all tests in the class. Suitable for expensive setup.LifecycleRuns a method once before all tests in the class. Suitable for expensive setup.
#[BeforeTest]#[BeforeTest(int $priority = 0)]Runs a method before each test in the class.LifecycleRuns a method before each test in the class.
#[Bench]#[Bench(array $callables, array $arguments = [], int $warmup = 1, int $calls = 1_000, int $iterations = 10)]Declares a benchmark comparing the method's performance against alternative implementations.BenchDeclares a benchmark comparing the method's performance against alternative implementations.
#[Covers]#[Covers(string $classOrFunction, ?string $method = null)]Restricts which source code this test is credited with.CodecovRestricts which source code this test is credited with.
#[CoversNothing]#[CoversNothing]Excludes a test from coverage statistics.CodecovExcludes a test from coverage statistics.
#[DatabaseMigrations]#[DatabaseMigrations(bool $seed = false, ?string $seeder = null, bool $dropViews = false, bool $dropTypes = false)]Runs migrate:fresh before each test and rolls the migrations back after it.LaravelRuns migrate:fresh before each test and rolls the migrations back after it.
#[DatabaseTransactions]#[DatabaseTransactions(?array $connections = null)]Wraps each test in a transaction that is rolled back, without running migrations.LaravelWraps each test in a transaction that is rolled back, without running migrations.
#[DatabaseTruncation]#[DatabaseTruncation(bool $seed = false, ?string $seeder = null, bool $dropViews = false, bool $dropTypes = false, ?array $connections = null, ?array $tables = null, ?array $exceptTables = null)]Truncates tables before each test.LaravelTruncates tables before each test.
#[DataCross]#[DataCross(DataProviderAttribute ...$providers)]Creates all possible combinations from providers (cartesian product).DataCreates all possible combinations from providers (cartesian product).
#[DataProvider]#[DataProvider(callable|string $provider)]Provides data for a parameterized test from a method or callable.DataProvides data for a parameterized test from a method or callable.
#[DataSet]#[DataSet(array $arguments, ?string $name = null)]Declares a set of arguments for a parameterized test. Can be used multiple times — each attribute creates a separate test run.DataDeclares a set of arguments for a parameterized test. Can be used multiple times — each attribute creates a separate test run.
#[DataUnion]#[DataUnion(DataProviderAttribute ...$providers)]Merges data from multiple providers into a single sequential set.DataMerges data from multiple providers into a single sequential set.
#[DataZip]#[DataZip(DataProviderAttribute ...$providers)]Pairs up providers element by element.DataPairs up providers element by element.
#[ExpectErrorHandlerChange]#[ExpectErrorHandlerChange]Declares that the test changes the error handler stack on purpose.Error HandlerDeclares that the test changes the error handler stack on purpose.
#[ExpectException]#[ExpectException(string $class)]Attribute form of Expect::exception()Expect::exception(string|\Throwable $classOrObject, bool $same = false): ExpectedExceptionExpects the test to throw the given exception..assertAttribute form of Expect::exception()Expect::exception(string|\Throwable $classOrObject, bool $same = false): ExpectedExceptionExpects the test to throw the given exception..
#[ExpectNoAssertions]#[ExpectNoAssertions]Declares that a test intentionally performs no assertions.assertDeclares that a test intentionally performs no assertions.
#[Group]#[Group(string ...$names)]Labels a class, method, or function with one or more group names for selective filtering.filterLabels a class, method, or function with one or more group names for selective filtering.
#[RefreshDatabase]#[RefreshDatabase(bool $seed = false, ?string $seeder = null, bool $dropViews = false, bool $dropTypes = false, ?array $connections = null)]Migrates the database once, then wraps each test in a transaction that is rolled back.LaravelMigrates the database once, then wraps each test in a transaction that is rolled back.
#[Repeat]#[Repeat(int $times = 2, int $maxFailures = 0, bool $markFlaky = true)]Runs a test a fixed number of times and decides the outcome by a failure threshold.RepeatRuns a test a fixed number of times and decides the outcome by a failure threshold.
#[Retry]#[Retry(int $maxAttempts = 3, bool $markFlaky = true)]Declares a retry policy for a test on failure.AssertDeclares a retry policy for a test on failure.
#[RunInFiber]#[RunInFiber(Schedule $schedule = Schedule::Solo)]Runs a test (on a method) or a whole case (on a class) in fibers, under Testo's cooperative scheduler.FiberRuns a test (on a method) or a whole case (on a class) in fibers, under Testo's cooperative scheduler.
#[RunInRevolt]#[RunInRevolt()]Runs the test on the Revolt event loop.RevoltRuns the test on the Revolt event loop.
#[Skip]#[Skip(string $reason = '')]Marks a test, a test class or a test function as skipped without running it.SkipMarks a test, a test class or a test function as skipped without running it.
#[Test]#[Test()]Explicitly marks a method, function, or class as a test.TestExplicitly marks a method, function, or class as a test.
#[TestInline]#[TestInline(array $arguments, mixed $result = null)]Declares an inline test on a method or function.InlineDeclares an inline test on a method or function.
#[TestRectorFixtures]#[TestRectorFixtures(string ...$paths)]Declares the fixtures that exercise a Rector rule.RectorTestingDeclares the fixtures that exercise a Rector rule.
#[WithoutErrorHandler]#[WithoutErrorHandler]Takes the test out of the plugin's reach.Error HandlerTakes the test out of the plugin's reach.