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

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

PHPUnit (ecosystem: on when composer.lock has phpunit/phpunit). Also in [format](/docs/rules/format/phpunit) (1).

**[add-allow-mock-objects-attribute](/docs/rules/lint/phpunit/add-allow-mock-objects-attribute)**

Add #[AllowMockObjectsWithoutExpectations] to PHPUnit test classes whose mocks have no expectations.

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[add-closure-return-type-from-assert](/docs/rules/lint/phpunit/add-closure-return-type-from-assert)**

Add return type to closures narrowed by assertInstanceOf() inside PHPUnit test case classes

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-data-provider-allow-mock-objects](/docs/rules/lint/phpunit/add-data-provider-allow-mock-objects)**

Add #[AllowMockObjectsWithoutExpectations] attribute to PHPUnit test classes that have methods with data providers and mock objects without expectations

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[add-data-provider-iterator-return-type](/docs/rules/lint/phpunit/add-data-provider-iterator-return-type)**

Add Iterator type on known PHPUnit data providers

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-depended-test-return-type](/docs/rules/lint/phpunit/add-depended-test-return-type)**

Add return type declaration to a test method that returns type

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-does-not-perform-assertions](/docs/rules/lint/phpunit/add-does-not-perform-assertions)**

Tests without assertion will have #[DoesNotPerformAssertions] attribute, or @doesNotPerformAssertions annotation on PHPUnit below 10

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-instanceof-assert](/docs/rules/lint/phpunit/add-instanceof-assert)**

Add an assertInstanceOf() before a nullable object is used in a PHPUnit test.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[add-instanceof-assert-for-argument](/docs/rules/lint/phpunit/add-instanceof-assert-for-argument)**

Add explicit instance assert between above nullable object pass

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[add-mock-intersection-param](/docs/rules/lint/phpunit/add-mock-intersection-param)**

Add a MockObject intersection @param docblock with the mocked class, based on the mock passed in the private method call

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[add-mock-intersection-type](/docs/rules/lint/phpunit/add-mock-intersection-type)**

Add `MockObject&Foo` / `Stub&Foo` intersection types to PHPDoc of mock and stub properties, params and returns.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[add-mock-object-type](/docs/rules/lint/phpunit/add-mock-object-type)**

Change param type of a private test method to MockObject, when expects() is called on it

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[add-param-type-depends](/docs/rules/lint/phpunit/add-param-type-depends)**

Add param type declaration based on @depends test method return type

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-parent-test-constructor](/docs/rules/lint/phpunit/add-parent-test-constructor)**

PHPUnit\Framework\TestCase requires a parent constructor call

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-property-type-container-get](/docs/rules/lint/phpunit/add-property-type-container-get)**

Add strict typed property to a private test case property based on its @var object type, when assigned via container fetch in setUp()

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-property-type-create-mock](/docs/rules/lint/phpunit/add-property-type-create-mock)**

Add "PHPUnit\Framework\MockObject\MockObject" typed property from assigned mock to clearly separate from real objects

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-property-type-setup](/docs/rules/lint/phpunit/add-property-type-setup)**

Add strict typed property based on setUp() strict typed assigns in TestCase

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-property-type-setup-docblock](/docs/rules/lint/phpunit/add-property-type-setup-docblock)**

Add property type in PHPUnit test from docblock, if defined in setUp() method

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-prophecy-trait](/docs/rules/lint/phpunit/add-prophecy-trait)**

Add Prophecy trait for method using $this->prophesize()

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[add-return-type-from-mock-object](/docs/rules/lint/phpunit/add-return-type-from-mock-object)**

Add known property and return MockObject types

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-see-test-tag](/docs/rules/lint/phpunit/add-see-test-tag)**

Add @see annotation test of the class for faster jump to test. Make it FQN, so it stays in the annotation, not in the PHP source code.

Not in any preset. In Rector's `rector/rector-preset` set. Needs the `phpunit` extension. Safe fix.

**[add-stub-intersection-type](/docs/rules/lint/phpunit/add-stub-intersection-type)**

Add a Stub intersection @var docblock with the stubbed class to a native Stub property

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[add-test-void-return](/docs/rules/lint/phpunit/add-test-void-return)**

Add void to PHPUnit test methods

In the `lint-strict` preset. In Rector's `rector/type-declaration` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-will-return-callback-false-fallback](/docs/rules/lint/phpunit/add-will-return-callback-false-fallback)**

Add a "return false" fallback to a willReturnCallback() closure that only returns booleans, but can fall through without a return

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[add-will-return-callback-param-type](/docs/rules/lint/phpunit/add-will-return-callback-param-type)**

Decorate callbacks and arrow functions in willReturnCallback() with known param/return types based on reflection method

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-any-matcher](/docs/rules/lint/phpunit/no-any-matcher)**

Change deprecated `$this->any()` matcher assign to direct `new AnyInvokedCount()`

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[no-assert-class-has-attribute](/docs/rules/lint/phpunit/no-assert-class-has-attribute)**

Replace removed assertClassHas*Attribute() with property_exists()

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-assert-contains-on-string](/docs/rules/lint/phpunit/no-assert-contains-on-string)**

Change assertContains()/assertNotContains() method to new string and iterable alternatives

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[no-assert-contains-only](/docs/rules/lint/phpunit/no-assert-contains-only)**

Replaces `Assert::assertContainsOnly()` calls with type-specific `Assert::assertContainsOnly*()` calls

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[no-assert-internal-type](/docs/rules/lint/phpunit/no-assert-internal-type)**

Replace assertInternalType() with the dedicated assertIs*() assertion.

In the `lint-strict` preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-assert-is-type](/docs/rules/lint/phpunit/no-assert-is-type)**

Replaces `Assert::isType()` calls with type-specific `Assert::is*()` calls

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[no-assert-same-type-mismatch](/docs/rules/lint/phpunit/no-assert-same-type-mismatch)**

Correct expected type in assertSame() method to match strict type of passed variable

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[no-at-matcher](/docs/rules/lint/phpunit/no-at-matcher)**

Replace at() method call with desired matcher

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-bare-mock-assign](/docs/rules/lint/phpunit/no-bare-mock-assign)**

Use a `createMock()` result directly where it is used once, instead of assigning it to a variable first

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[no-bare-mock-builder](/docs/rules/lint/phpunit/no-bare-mock-builder)**

Remove getMockBuilder() to createMock()

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality` sets. Needs the `phpunit` extension. Safe fix.

**[no-data-provider-test-prefix](/docs/rules/lint/phpunit/no-data-provider-test-prefix)**

Data provider methods cannot start with "test" prefix

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-empty-test](/docs/rules/lint/phpunit/no-empty-test)**

Remove empty test methods

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-entity-mock](/docs/rules/lint/phpunit/no-entity-mock)**

Move from entity mock, to direct use of class instance and setters

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-expected-exception-annotation](/docs/rules/lint/phpunit/no-expected-exception-annotation)**

Replace @expectedException annotations with expectException() calls.

In the `lint-strict` preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-expects-any](/docs/rules/lint/phpunit/no-expects-any)**

Remove `expect($this->any())` from mocks as it has no added value

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality` sets. Needs the `phpunit` extension. Safe fix.

**[no-final-constructor-override](/docs/rules/lint/phpunit/no-final-constructor-override)**

Remove override final construct test case

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[no-flipped-assertion](/docs/rules/lint/phpunit/no-flipped-assertion)**

Turns accidentally flipped assert order to right one, with expected expr to left

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-float-delta-parameter](/docs/rules/lint/phpunit/no-float-delta-parameter)**

Change assertEquals()/assertSame() method using float on expected argument to new specific alternatives.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-mock-builder-set-methods](/docs/rules/lint/phpunit/no-mock-builder-set-methods)**

Remove "setMethods()" method as never used, move methods to "addMethods()" if non-existent or @method magic

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-mock-intersection-property](/docs/rules/lint/phpunit/no-mock-intersection-property)**

Make properties in tests with intersection mock object either object type or mock type

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-negated-assertion](/docs/rules/lint/phpunit/no-negated-assertion)**

Turns not-operator comparisons to their method name alternatives in PHPUnit TestCase

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[no-scenario-annotation](/docs/rules/lint/phpunit/no-scenario-annotation)**

Change `@scenario` annotation to `@test` in a test class

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[no-setup-override-attribute](/docs/rules/lint/phpunit/no-setup-override-attribute)**

Remove override attribute, if setUp()/tearDown() references parent call to improve readability

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-stub-with-expectations](/docs/rules/lint/phpunit/no-stub-with-expectations)**

Change createStub() to createMock(), when the created variable is passed to a method that requires MockObject type

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[no-test-constructor](/docs/rules/lint/phpunit/no-test-constructor)**

Replace or remove __construct() in PHPUnit test cases; use setUp().

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-test-listener](/docs/rules/lint/phpunit/no-test-listener)**

Refactor "*TestListener.php" to particular "*Hook.php" files

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[no-unused-mock](/docs/rules/lint/phpunit/no-unused-mock)**

Remove standalone method calls with no effect

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-unused-mock-property](/docs/rules/lint/phpunit/no-unused-mock-property)**

Remove never used property mock, only to set expectations

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-value-object-mock](/docs/rules/lint/phpunit/no-value-object-mock)**

Use a real instance instead of a mock for entities and simple value objects in tests.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[no-with-consecutive](/docs/rules/lint/phpunit/no-with-consecutive)**

Refactor deprecated withConsecutive() to willReturnCallback() structure

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-assert](/docs/rules/lint/phpunit/prefer-assert)**

Turns assert() calls in tests to PHPUnit assert method alternative

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-array-has-key](/docs/rules/lint/phpunit/prefer-assert-array-has-key)**

Turns assertTrue() + isset() comparisons to more precise assertArrayHasKey() method

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-contains-equals](/docs/rules/lint/phpunit/prefer-assert-contains-equals)**

Change assertContains()/assertNotContains() with non-strict comparison to new specific alternatives

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-count](/docs/rules/lint/phpunit/prefer-assert-count)**

Replaces use of assertSame and assertEquals on Countable objects with count method

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-instanceof](/docs/rules/lint/phpunit/prefer-assert-instanceof)**

Turns instanceof comparisons to their method name alternatives in PHPUnit TestCase

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-instanceof-over-empty](/docs/rules/lint/phpunit/prefer-assert-instanceof-over-empty)**

Change assertNotEmpty() and assertNotNull() on an object to more clear assertInstanceof()

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-instances-of](/docs/rules/lint/phpunit/prefer-assert-instances-of)**

Simplify unnecessary foreach check of instances

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-matches-regular-expression](/docs/rules/lint/phpunit/prefer-assert-matches-regular-expression)**

Turns `preg_match` comparisons to their method name alternatives in PHPUnit TestCase

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-assert-null-true-false](/docs/rules/lint/phpunit/prefer-assert-null-true-false)**

Turns same bool and null comparisons to their method name alternatives in PHPUnit TestCase

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-assert-same](/docs/rules/lint/phpunit/prefer-assert-same)**

PHPUnit methods like `assertSame` should be used instead of `assertEquals`.

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-assert-string-contains](/docs/rules/lint/phpunit/prefer-assert-string-contains)**

Turns `strpos`/`stripos` comparisons to their method name alternatives in PHPUnit TestCase

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-assert-true-false](/docs/rules/lint/phpunit/prefer-assert-true-false)**

Change $this->assertSame(true, ...) to assertTrue()

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-attribute-over-annotation](/docs/rules/lint/phpunit/prefer-attribute-over-annotation)**

Change annotations with value to attribute

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-attributes](/docs/rules/lint/phpunit/prefer-attributes)**

PHPUnit attributes must be used over their respective PHPDoc-based annotations.

Not in any preset. Needs the `phpunit` extension. Safe fix.

**[prefer-camel-case-test-names](/docs/rules/lint/phpunit/prefer-camel-case-test-names)**

Changes PHPUnit test methods to camel case

Not in any preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-comparison-assertion](/docs/rules/lint/phpunit/prefer-comparison-assertion)**

Replace assertTrue()/assertFalse() on a comparison, instanceof, isset, count or strpos with the specific assertion.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-covers-attribute](/docs/rules/lint/phpunit/prefer-covers-attribute)**

Change covers annotations with value to attribute

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-create-mock](/docs/rules/lint/phpunit/prefer-create-mock)**

Replace getMock*() with createMock().

In the `lint-strict` preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-create-stub](/docs/rules/lint/phpunit/prefer-create-stub)**

Use createStub() instead of createMock() when no expectations are set.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-create-stub-argument](/docs/rules/lint/phpunit/prefer-create-stub-argument)**

Use createStub() over createMock() when used as argument or array value and does not add any mock requirements

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-create-stub-expression](/docs/rules/lint/phpunit/prefer-create-stub-expression)**

Replace createMock() assigned to variable that is only used as arg with no expectations, to createStub()

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-create-stub-in-coalesce](/docs/rules/lint/phpunit/prefer-create-stub-in-coalesce)**

Use createStub() over createMock() when used as argument/array item coalesce ?? fallback

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-data-provider](/docs/rules/lint/phpunit/prefer-data-provider)**

Replace testWith annotation to data provider.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-data-provider-attribute](/docs/rules/lint/phpunit/prefer-data-provider-attribute)**

Change dataProvider annotations to attribute

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-dedicated-assertion](/docs/rules/lint/phpunit/prefer-dedicated-assertion)**

Use dedicated PHPUnit assertions such as assertFileExists() instead of assertTrue(file_exists()).

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-depends-attribute](/docs/rules/lint/phpunit/prefer-depends-attribute)**

Change depends annotations with value to attribute

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-direct-assert](/docs/rules/lint/phpunit/prefer-direct-assert)**

Change $this->assertThat($value, $this->*()) to direct $this->assert*() method

Not in any preset. Needs the `phpunit` extension. Safe fix.

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

Replace setExpectedException*() with expectException*().

In the `lint-strict` preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-expect-php-error](/docs/rules/lint/phpunit/prefer-expect-php-error)**

Use explicit API for expecting PHP errors, warnings, and notices

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[prefer-inline-create-stub](/docs/rules/lint/phpunit/prefer-inline-create-stub)**

Inline stub property only used to pass as new argument to a method call

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-local-over-setup-property](/docs/rules/lint/phpunit/prefer-local-over-setup-property)**

Turn property used only in setUp() to variable

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-mock-intersection-return](/docs/rules/lint/phpunit/prefer-mock-intersection-return)**

Change a MockObject @return union docblock to an intersection type

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-named-data-provider-keys](/docs/rules/lint/phpunit/prefer-named-data-provider-keys)**

Change the array-index names to the argument name of the dataProvider

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[prefer-namespaced](/docs/rules/lint/phpunit/prefer-namespaced)**

PHPUnit classes MUST be used in namespaced version, e.g. `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-narrow-will-return-callback](/docs/rules/lint/phpunit/prefer-narrow-will-return-callback)**

Narrow single-value match willReturnCallback() to with() and willReturn() call

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-narrow-with-consecutive](/docs/rules/lint/phpunit/prefer-narrow-with-consecutive)**

Narrow identical withConsecutive() and willReturnOnConsecutiveCalls() to single call

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-new-assertion-names](/docs/rules/lint/phpunit/prefer-new-assertion-names)**

Rename deprecated PHPUnit assertions like `assertFileNotExists` to new methods like `assertFileDoesNotExist`.

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-property-assertions](/docs/rules/lint/phpunit/prefer-property-assertions)**

Split object casted to array to assert public properties to standalone assert calls

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-requires-attribute](/docs/rules/lint/phpunit/prefer-requires-attribute)**

Change Requires annotations with values to attributes

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-self-call](/docs/rules/lint/phpunit/prefer-self-call)**

Changes PHPUnit calls from $this->assert*() to self::assert*()

Not in any preset. Needs the `phpunit` extension. Safe fix.

**[prefer-short-will-return](/docs/rules/lint/phpunit/prefer-short-will-return)**

Use willReturn() and similar instead of will($this->returnValue()).

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-simple-callback-assert](/docs/rules/lint/phpunit/prefer-simple-callback-assert)**

Replaces use of with, callback and sole assertSame() to simple equalTo() matcher

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-simple-mock-expectation](/docs/rules/lint/phpunit/prefer-simple-mock-expectation)**

Replace withConsecutive()/willReturnCallback() that cover one value with with()/willReturn().

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-simple-with-matcher](/docs/rules/lint/phpunit/prefer-simple-with-matcher)**

Simplify ->with() matchers: plain values instead of equalTo(), isInstanceOf() instead of a callback.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-snake-case-test-names](/docs/rules/lint/phpunit/prefer-snake-case-test-names)**

Changes PHPUnit test methods to snake case

Not in any preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-specific-assert-equals](/docs/rules/lint/phpunit/prefer-specific-assert-equals)**

Change assertEquals()/assertNotEquals() method parameters to new specific alternatives

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[prefer-specific-assertions](/docs/rules/lint/phpunit/prefer-specific-assertions)**

PHPUnit assertion method calls like `->assertSame(true, $foo)` should be written with dedicated method like `->assertTrue($foo)`.

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-specific-true-false-assertion](/docs/rules/lint/phpunit/prefer-specific-true-false-assertion)**

Turns true/false comparisons to their method name alternatives in PHPUnit TestCase when possible

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-narrow-asserts` sets. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-specific-will-method](/docs/rules/lint/phpunit/prefer-specific-will-method)**

Changes $mock->will() call to more specific method

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-standalone-asserts-over-callback](/docs/rules/lint/phpunit/prefer-standalone-asserts-over-callback)**

Replaces identical compare in $this->callable() sole return to standalone PHPUnit asserts that show more detailed failure messages

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-stub-var](/docs/rules/lint/phpunit/prefer-stub-var)**

Update the @var docblock of a property changed to a Stub native type, from MockObject to Stub

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/composer-based`, `rector-phpunit/phpunit-code-quality`, `rector-phpunit/phpunit-mock-to-stub` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-test-attribute](/docs/rules/lint/phpunit/prefer-test-attribute)**

Suggests using PHPUnit's `#[Test]` attribute instead of the `test` method name prefix.

In the `lint-recommended` preset and every stricter one. Needs the `phpunit` extension. Safe fix.

**[prefer-test-prefix](/docs/rules/lint/phpunit/prefer-test-prefix)**

Replace @test with prefixed function

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-test-with-attribute](/docs/rules/lint/phpunit/prefer-test-with-attribute)**

Change @testWith() annotation to #[TestWith] attribute

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-this-assert](/docs/rules/lint/phpunit/prefer-this-assert)**

Changes PHPUnit calls from Assert::assert*() to $this->assert*()

Not in any preset. Needs the `phpunit` extension. Safe fix.

**[prefer-this-call](/docs/rules/lint/phpunit/prefer-this-call)**

Changes PHPUnit calls from self::assert*() to $this->assert*()

In the `lint-strict` preset. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[prefer-ticket-attribute](/docs/rules/lint/phpunit/prefer-ticket-attribute)**

Change annotations with value to attribute

Not in any preset. In Rector's `rector-phpunit/annotations-to-attributes`, `rector-phpunit/composer-based` sets. Needs the `phpunit` extension. Safe fix.

**[prefer-will-return-callback](/docs/rules/lint/phpunit/prefer-will-return-callback)**

Merge ->with($this->callback()) and ->willReturn() into willReturnCallback().

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-with-is-instance-of](/docs/rules/lint/phpunit/prefer-with-is-instance-of)**

Replaces use of with, callable and instance assert to simple isInstanceOf() method

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[prefer-yield-data-provider](/docs/rules/lint/phpunit/prefer-yield-data-provider)**

Turns array return to yield in data providers

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[require-array-key-assert](/docs/rules/lint/phpunit/require-array-key-assert)**

Add assertArrayHasKey() call for array access with string key, that was not validated before

Not in any preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-assertion-style](/docs/rules/lint/phpunit/require-assertion-style)**

Calls to `PHPUnit\Framework\TestCase` static methods (like assertions) must all be of the same type, either `$this->`, `self::` or `static::`.

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-covers](/docs/rules/lint/phpunit/require-covers)**

Adds a default `@coversNothing` annotation to PHPUnit test classes that have no `@covers*` annotation.

Not in any preset. Needs the `phpunit` extension. Safe fix.

**[require-data-provider-naming](/docs/rules/lint/phpunit/require-data-provider-naming)**

Data provider names must match the name of the test.

Not in any preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-data-provider-newlines](/docs/rules/lint/phpunit/require-data-provider-newlines)**

Change data provider in PHPUnit test case to newline per item

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[require-data-provider-order](/docs/rules/lint/phpunit/require-data-provider-order)**

Data provider method must be placed after/before the last/first test where used.

In the `lint-recommended` preset and every stricter one. Needs the `phpunit` extension. Safe fix.

**[require-exact-test-argument-type](/docs/rules/lint/phpunit/require-exact-test-argument-type)**

Correct expected type in setter of tests, if param type is strictly defined

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[require-explicit-mock-expects](/docs/rules/lint/phpunit/require-explicit-mock-expects)**

Add explicit expects() to method() mock calls, to make expectations count explicit

Not in any preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-final-test-case](/docs/rules/lint/phpunit/require-final-test-case)**

Make PHPUnit test case final

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality`, `rector/rector-preset` sets. Needs the `phpunit` extension. Safe fix.

**[require-internal](/docs/rules/lint/phpunit/require-internal)**

All PHPUnit test classes should be marked as internal.

Not in any preset. Needs the `phpunit` extension. Safe fix.

**[require-iterable-data-provider](/docs/rules/lint/phpunit/require-iterable-data-provider)**

The return type of PHPUnit data provider must be `iterable`.

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-method-casing](/docs/rules/lint/phpunit/require-method-casing)**

Enforce camel (or snake) case for PHPUnit test methods, following configuration.

In the `lint-recommended` preset and every stricter one. Needs the `phpunit` extension. Safe fix.

**[require-mock-expects](/docs/rules/lint/phpunit/require-mock-expects)**

Add an explicit expects() to mocked method calls.

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[require-protected-setup](/docs/rules/lint/phpunit/require-protected-setup)**

Changes the visibility of the `setUp()` and `tearDown()` functions of PHPUnit to `protected`, to match the PHPUnit TestCase.

Not in any preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-public-data-provider](/docs/rules/lint/phpunit/require-public-data-provider)**

Change data provider methods to public

Not in any preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Safe fix.

**[require-size](/docs/rules/lint/phpunit/require-size)**

All PHPUnit test cases should have `@small`, `@medium` or `@large` annotation to enable run time limits.

Not in any preset. Needs the `phpunit` extension. Safe fix.

**[require-static-data-provider](/docs/rules/lint/phpunit/require-static-data-provider)**

Make PHPUnit data providers static.

In the `lint-strict` preset. In Rector's `rector-phpunit/composer-based` set. Needs the `phpunit` extension. Unsafe fix: it can change behavior.

**[require-strict-types-in-tests](/docs/rules/lint/phpunit/require-strict-types-in-tests)**

Add `declare(strict_types=1)` to PHPUnit test class file

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[require-string-assert-argument](/docs/rules/lint/phpunit/require-string-assert-argument)**

Cast 2nd argument in assertStringContainsString() to a string if not yet

In the `lint-recommended` preset and every stricter one. In Rector's `rector-phpunit/phpunit-code-quality` set. Needs the `phpunit` extension. Safe fix.

**[require-test-annotation-style](/docs/rules/lint/phpunit/require-test-annotation-style)**

Mark tests consistently: a `test` prefix or a @test annotation.

In the `lint-strict` preset. Needs the `phpunit` extension. Unsafe fix: it can change behavior.
