---
title: "lint/pest"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

Pest (ecosystem: on when composer.lock has pestphp/pest).

**[no-before-all-in-describe](/docs/rules/lint/pest/no-before-all-in-describe)**

Replaces invalid beforeAll() and afterAll() hooks inside describe() with beforeEach() and afterEach()

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[no-invalid-repeat](/docs/rules/lint/pest/no-invalid-repeat)**

Normalizes invalid literal repeat() counts to 1

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[no-negated-boolean-matcher](/docs/rules/lint/pest/no-negated-boolean-matcher)**

Simplifies double-negative expectations like ->not->toBeFalse() to ->toBeTrue()

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[no-only](/docs/rules/lint/pest/no-only)**

Remove ->only() from Pest tests.

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[no-redundant-type-expectation](/docs/rules/lint/pest/no-redundant-type-expectation)**

Removes redundant literal type expectations when a later matcher keeps the chain meaningful

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[no-redundant-uses](/docs/rules/lint/pest/no-redundant-uses)**

Removes redundant local Pest uses already configured globally in tests/Pest.php

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[no-static-test-closure](/docs/rules/lint/pest/no-static-test-closure)**

Removes static from Pest test and hook callbacks that use the test case instance

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-chained-expect](/docs/rules/lint/pest/prefer-chained-expect)**

Chains consecutive expect() calls into a single chained expectation, combining calls on the same value and joining different values with ->and() (configurable)

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-dedicated-expectation](/docs/rules/lint/pest/prefer-dedicated-expectation)**

Use dedicated Pest matchers (toBeArray(), toStartWith(), toHaveCount(), ...) instead of expect(fn(...))->toBeTrue().

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-defer](/docs/rules/lint/pest/prefer-defer)**

Replaces deprecated ->tap() method with ->defer() for Pest v3 migration

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-each-modifier](/docs/rules/lint/pest/prefer-each-modifier)**

Converts foreach loops with expect() calls to use the ->each modifier

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-expect](/docs/rules/lint/pest/prefer-expect)**

Converts $this->assert*() calls to Pest expect() chains

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-extend](/docs/rules/lint/pest/prefer-extend)**

Converts uses() and pest()->uses() to pest()->extend() for classes and pest()->use() for traits

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-filesystem-matchers](/docs/rules/lint/pest/prefer-filesystem-matchers)**

Simplifies combined filesystem checks to single Pest matchers

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-not-modifier](/docs/rules/lint/pest/prefer-not-modifier)**

Simplifies negated expectations by flipping the matcher (e.g., expect(!$x)->toBeTrue() becomes expect($x)->toBeFalse())

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-sequence](/docs/rules/lint/pest/prefer-sequence)**

Converts consecutive indexed expect() calls to sequence()

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-simpler-expectation](/docs/rules/lint/pest/prefer-simpler-expectation)**

Simplify Pest expectations: expect($a > $b)->toBeTrue() becomes expect($a)->toBeGreaterThan($b), and similar.

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-specific-expectations](/docs/rules/lint/pest/prefer-specific-expectations)**

Use toBeTrue()/toBeFalse()/toBeNull() instead of toBe(true&#124;false&#124;null).

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-strict-equality-matchers](/docs/rules/lint/pest/prefer-strict-equality-matchers)**

Converts strict equality expressions to toBe() matcher

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-be-alpha](/docs/rules/lint/pest/prefer-to-be-alpha)**

Converts ctype_alpha() checks to toBeAlpha() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-alpha-numeric](/docs/rules/lint/pest/prefer-to-be-alpha-numeric)**

Converts ctype_alnum() checks to toBeAlphaNumeric() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-between](/docs/rules/lint/pest/prefer-to-be-between)**

Converts expect($value >= $min &amp;&amp; $value &lt;= $max)->toBeTrue() to expect($value)->toBeBetween($min, $max)

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-be-digits](/docs/rules/lint/pest/prefer-to-be-digits)**

Converts ctype_digit() checks to toBeDigits() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-directory](/docs/rules/lint/pest/prefer-to-be-directory)**

Converts is_dir() checks to toBeDirectory() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-empty](/docs/rules/lint/pest/prefer-to-be-empty)**

Converts empty checks and count-zero comparisons to toBeEmpty() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-file](/docs/rules/lint/pest/prefer-to-be-file)**

Converts is_file() checks to toBeFile() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-in](/docs/rules/lint/pest/prefer-to-be-in)**

Converts strict in_array() checks to the toBeIn() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-infinite](/docs/rules/lint/pest/prefer-to-be-infinite)**

Converts is_infinite() checks to toBeInfinite() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-instance-of](/docs/rules/lint/pest/prefer-to-be-instance-of)**

Converts expect($obj instanceof User)->toBeTrue() to expect($obj)->toBeInstanceOf(User::class)

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-be-json](/docs/rules/lint/pest/prefer-to-be-json)**

Converts json_decode() null checks to toBeJson() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-list](/docs/rules/lint/pest/prefer-to-be-list)**

Converts array_is_list() checks to toBeList() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-lowercase](/docs/rules/lint/pest/prefer-to-be-lowercase)**

Converts strtolower() equality checks to toBeLowercase() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-nan](/docs/rules/lint/pest/prefer-to-be-nan)**

Converts is_nan() checks to toBeNan() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-truthy-falsy](/docs/rules/lint/pest/prefer-to-be-truthy-falsy)**

Converts bool cast assertions to toBeTruthy()/toBeFalsy() matchers

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-be-uppercase](/docs/rules/lint/pest/prefer-to-be-uppercase)**

Converts strtoupper() equality checks to toBeUppercase() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-url](/docs/rules/lint/pest/prefer-to-be-url)**

Converts filter_var($url, FILTER_VALIDATE_URL) checks to toBeUrl() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-be-uuid](/docs/rules/lint/pest/prefer-to-be-uuid)**

Converts UUID regex validation to toBeUuid() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-contain](/docs/rules/lint/pest/prefer-to-contain)**

Converts in_array() checks to toContain() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-contain-equal](/docs/rules/lint/pest/prefer-to-contain-equal)**

Converts in_array(..., false) checks to toContainEqual() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-contain-only-instances-of](/docs/rules/lint/pest/prefer-to-contain-only-instances-of)**

Converts ->each->toBeInstanceOf() pattern to toContainOnlyInstancesOf() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-end-with](/docs/rules/lint/pest/prefer-to-end-with)**

Converts str_ends_with() checks to toEndWith() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-equal-canonicalizing](/docs/rules/lint/pest/prefer-to-equal-canonicalizing)**

Converts sort-then-compare to toEqualCanonicalizing() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-equal-with-delta](/docs/rules/lint/pest/prefer-to-equal-with-delta)**

Converts expect(abs($a - $b) &lt; $delta)->toBeTrue() to expect($a)->toEqualWithDelta($b, $delta)

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-have-count](/docs/rules/lint/pest/prefer-to-have-count)**

Converts expect(count($arr))->toBe(5) to expect($arr)->toHaveCount(5)

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-have-key](/docs/rules/lint/pest/prefer-to-have-key)**

Converts array_key_exists() checks to toHaveKey() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-have-keys](/docs/rules/lint/pest/prefer-to-have-keys)**

Converts chained toHaveKey() calls to toHaveKeys() with array of keys

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-have-length](/docs/rules/lint/pest/prefer-to-have-length)**

Converts strlen()/mb_strlen() comparisons to toHaveLength() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-have-method-on-class](/docs/rules/lint/pest/prefer-to-have-method-on-class)**

Changes expect($object)->toHaveMethod() to expect($object::class)->toHaveMethod() for Pest v3

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-have-properties](/docs/rules/lint/pest/prefer-to-have-properties)**

Converts chained toHaveProperty() calls to toHaveProperties() with array of properties

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-have-property](/docs/rules/lint/pest/prefer-to-have-property)**

Converts property_exists() checks to toHaveProperty() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-have-same-size](/docs/rules/lint/pest/prefer-to-have-same-size)**

Converts expect(count($a))->toBe(count($b)) to expect($a)->toHaveSameSize($b)

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-match](/docs/rules/lint/pest/prefer-to-match)**

Converts expect(preg_match("/pattern/", $str))->toBe(1) to expect($str)->toMatch("/pattern/")

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-match-array](/docs/rules/lint/pest/prefer-to-match-array)**

Converts multiple array element assertions to toMatchArray() matcher

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-match-object](/docs/rules/lint/pest/prefer-to-match-object)**

Converts consecutive toHaveProperty() with values to toMatchObject() matcher

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-to-start-with](/docs/rules/lint/pest/prefer-to-start-with)**

Converts str_starts_with() checks to toStartWith() matcher

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[prefer-to-throw](/docs/rules/lint/pest/prefer-to-throw)**

Use expect()->toThrow() instead of expectException() or try/catch in Pest tests.

In the `coding-style` set. Safe fix. Runs when pest is installed.

**[prefer-type-matchers](/docs/rules/lint/pest/prefer-type-matchers)**

Converts expect(is_array($x))->toBeTrue() to expect($x)->toBeArray()

In the `coding-style` set. Unsafe fix: it can change behaviour. Runs when pest is installed.

**[require-type-matcher-first](/docs/rules/lint/pest/require-type-matcher-first)**

Ensure type-check matchers (e.g. toBeInt, toBeInstanceOf) appear before value assertions in expect() chains and consecutive expects

In the `coding-style` set. Safe fix. Runs when pest is installed.
