lint/phpunit
PHPUnit (ecosystem: on when composer.lock has phpunit/phpunit). Also in format (1).
add-allow-mock-objects-attribute
Add #[AllowMockObjectsWithoutExpectations] to PHPUnit test classes whose mocks have no expectations.
Not in any set. Safe fix. Runs when phpunit is installed.
add-closure-return-type-from-assert
Add return type to closures narrowed by assertInstanceOf() inside PHPUnit test case classes
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
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 set. Safe fix. Runs when phpunit is installed.
add-data-provider-iterator-return-type
Add Iterator type on known PHPUnit data providers
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-depended-test-return-type
Add return type declaration to a test method that returns type
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-instanceof-assert
Add an assertInstanceOf() before a nullable object is used in a PHPUnit test.
In the code-quality set. Safe fix. Runs when phpunit is installed.
add-instanceof-assert-for-argument
Add explicit instance assert between above nullable object pass
In the code-quality set. Safe fix. Runs when phpunit is installed.
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 code-quality set. Safe fix. Runs when phpunit is installed.
add-mock-intersection-type
Add MockObject&Foo / Stub&Foo intersection types to PHPDoc of mock and stub properties, params and returns.
In the code-quality set. Safe fix. Runs when phpunit is installed.
add-mock-object-type
Change param type of a private test method to MockObject, when expects() is called on it
Not in any set. Safe fix. Runs when phpunit is installed.
add-param-type-depends
Add param type declaration based on @depends test method return type
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
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 types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-property-type-create-mock
Add “PHPUnit\Framework\MockObject\MockObject” typed property from assigned mock to clearly separate from real objects
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-property-type-setup
Add strict typed property based on setUp() strict typed assigns in TestCase
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-property-type-setup-docblock
Add property type in PHPUnit test from docblock, if defined in setUp() method
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-return-type-from-mock-object
Add known property and return MockObject types
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
add-stub-intersection-type
Add a Stub intersection @var docblock with the stubbed class to a native Stub property
In the code-quality set. Safe fix. Runs when phpunit is installed.
add-test-void-return
Add void to PHPUnit test methods
In the types set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
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 code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed. Planned: not in Pun yet. Enabling it is a config error.
add-will-return-callback-param-type
Decorate callbacks and arrow functions in willReturnCallback() with known param/return types based on reflection method
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
no-any-matcher
Change deprecated $this->any() matcher assign to direct new AnyInvokedCount()
Not in any set. Safe fix. Runs when phpunit is installed. Planned: not in Pun yet. Enabling it is a config error.
no-assert-contains-only
Replaces Assert::assertContainsOnly() calls with type-specific Assert::assertContainsOnly*() calls
Not in any set. Safe fix. Runs when phpunit is installed.
no-assert-internal-type
Replace assertInternalType() with the dedicated assertIs*() assertion.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
no-assert-is-type
Replaces Assert::isType() calls with type-specific Assert::is*() calls
Not in any set. Safe fix. Runs when phpunit is installed.
no-assert-same-type-mismatch
Correct expected type in assertSame() method to match strict type of passed variable
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-at-matcher
Replace at() method call with desired matcher
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-bare-mock-assign
Use a createMock() result directly where it is used once, instead of assigning it to a variable first
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-bare-mock-builder
Remove getMockBuilder() to createMock()
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-empty-test
Remove empty test methods
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-entity-mock
Move from entity mock, to direct use of class instance and setters
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-expected-exception-annotation
Replace @expectedException annotations with expectException() calls.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
no-expects-any
Remove expect($this->any()) from mocks as it has no added value
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-final-constructor-override
Remove override final construct test case
Not in any set. Safe fix. Runs when phpunit is installed.
no-flipped-assertion
Turns accidentally flipped assert order to right one, with expected expr to left
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-float-delta-parameter
Change assertEquals()/assertSame() method using float on expected argument to new specific alternatives.
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-mock-intersection-property
Make properties in tests with intersection mock object either object type or mock type
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-negated-assertion
Turns not-operator comparisons to their method name alternatives in PHPUnit TestCase
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-setup-override-attribute
Remove override attribute, if setUp()/tearDown() references parent call to improve readability
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-stub-with-expectations
Change createStub() to createMock(), when the created variable is passed to a method that requires MockObject type
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-test-constructor
Replace or remove __construct() in PHPUnit test cases; use setUp().
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-unused-mock
Remove standalone method calls with no effect
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-unused-mock-property
Remove never used property mock, only to set expectations
In the code-quality set. Safe fix. Runs when phpunit is installed.
no-value-object-mock
Use a real instance instead of a mock for entities and simple value objects in tests.
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert
Turns assert() calls in tests to PHPUnit assert method alternative
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-array-has-key
Turns assertTrue() + isset() comparisons to more precise assertArrayHasKey() method
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-count
Replaces use of assertSame and assertEquals on Countable objects with count method
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-instanceof
Turns instanceof comparisons to their method name alternatives in PHPUnit TestCase
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-instanceof-over-empty
Change assertNotEmpty() and assertNotNull() on an object to more clear assertInstanceof()
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-instances-of
Simplify unnecessary foreach check of instances
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-null-true-false
Turns same bool and null comparisons to their method name alternatives in PHPUnit TestCase
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-assert-same
PHPUnit methods like assertSame should be used instead of assertEquals.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-assert-string-contains
Turns strpos/stripos comparisons to their method name alternatives in PHPUnit TestCase
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-assert-true-false
Change $this->assertSame(true, …) to assertTrue()
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-attribute-over-annotation
Change annotations with value to attribute
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-attributes
PHPUnit attributes must be used over their respective PHPDoc-based annotations.
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-comparison-assertion
Replace assertTrue()/assertFalse() on a comparison, instanceof, isset, count or strpos with the specific assertion.
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-covers-attribute
Change covers annotations with value to attribute
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-create-mock
Replace getMock*() with createMock().
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-create-stub
Use createStub() instead of createMock() when no expectations are set.
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-create-stub-argument
Use createStub() over createMock() when used as argument or array value and does not add any mock requirements
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-create-stub-expression
Replace createMock() assigned to variable that is only used as arg with no expectations, to createStub()
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-create-stub-in-coalesce
Use createStub() over createMock() when used as argument/array item coalesce ?? fallback
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-data-provider
Replace testWith annotation to data provider.
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-data-provider-attribute
Change dataProvider annotations to attribute
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-dedicated-assertion
Use dedicated PHPUnit assertions such as assertFileExists() instead of assertTrue(file_exists()).
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-depends-attribute
Change depends annotations with value to attribute
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-expect-exception
Replace setExpectedException*() with expectException*().
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-inline-create-stub
Inline stub property only used to pass as new argument to a method call
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-local-over-setup-property
Turn property used only in setUp() to variable
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-mock-intersection-return
Change a MockObject @return union docblock to an intersection type
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-named-data-provider-keys
Change the array-index names to the argument name of the dataProvider
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-namespaced
PHPUnit classes MUST be used in namespaced version, e.g. \PHPUnit\Framework\TestCase instead of \PHPUnit_Framework_TestCase.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-narrow-will-return-callback
Narrow single-value match willReturnCallback() to with() and willReturn() call
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-narrow-with-consecutive
Narrow identical withConsecutive() and willReturnOnConsecutiveCalls() to single call
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-new-assertion-names
Rename deprecated PHPUnit assertions like assertFileNotExists to new methods like assertFileDoesNotExist.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-property-assertions
Split object casted to array to assert public properties to standalone assert calls
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-requires-attribute
Change Requires annotations with values to attributes
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-short-will-return
Use willReturn() and similar instead of will($this->returnValue()).
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-simple-callback-assert
Replaces use of with, callback and sole assertSame() to simple equalTo() matcher
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-simple-mock-expectation
Replace withConsecutive()/willReturnCallback() that cover one value with with()/willReturn().
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-simple-with-matcher
Simplify ->with() matchers: plain values instead of equalTo(), isInstanceOf() instead of a callback.
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-specific-assertions
PHPUnit assertion method calls like ->assertSame(true, $foo) should be written with dedicated method like ->assertTrue($foo).
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-specific-true-false-assertion
Turns true/false comparisons to their method name alternatives in PHPUnit TestCase when possible
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-specific-will-method
Changes $mock->will() call to more specific method
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
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 code-quality set. Safe fix. Runs when phpunit is installed.
prefer-stub-var
Update the @var docblock of a property changed to a Stub native type, from MockObject to Stub
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-test-attribute
Suggests using PHPUnit’s #[Test] attribute instead of the test method name prefix.
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-test-prefix
Replace @test with prefixed function
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-test-with-attribute
Change @testWith() annotation to #[TestWith] attribute
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-this-call
Changes PHPUnit calls from self::assert*() to $this->assert*()
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
prefer-ticket-attribute
Change annotations with value to attribute
Not in any set. Safe fix. Runs when phpunit is installed.
prefer-will-return-callback
Merge ->with($this->callback()) and ->willReturn() into willReturnCallback().
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-with-is-instance-of
Replaces use of with, callable and instance assert to simple isInstanceOf() method
In the code-quality set. Safe fix. Runs when phpunit is installed.
prefer-yield-data-provider
Turns array return to yield in data providers
In the code-quality set. Safe fix. Runs when phpunit is installed.
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 code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
require-covers
Adds a default @coversNothing annotation to PHPUnit test classes that have no @covers* annotation.
Not in any set. Safe fix. Runs when phpunit is installed.
require-data-provider-naming
Data provider names must match the name of the test.
Not in any set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
require-data-provider-newlines
Change data provider in PHPUnit test case to newline per item
In the code-quality set. Safe fix. Runs when phpunit is installed.
require-data-provider-order
Data provider method must be placed after/before the last/first test where used.
In the coding-style set. Safe fix. Runs when phpunit is installed.
require-exact-test-argument-type
Correct expected type in setter of tests, if param type is strictly defined
In the code-quality set. Safe fix. Runs when phpunit is installed.
require-final-test-case
Make PHPUnit test case final
In the code-quality set. Safe fix. Runs when phpunit is installed.
require-internal
All PHPUnit test classes should be marked as internal.
Not in any set. Safe fix. Runs when phpunit is installed.
require-iterable-data-provider
The return type of PHPUnit data provider must be iterable.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
require-method-casing
Enforce camel (or snake) case for PHPUnit test methods, following configuration.
In the coding-style set. Safe fix. Runs when phpunit is installed.
require-mock-expects
Add an explicit expects() to mocked method calls.
In the code-quality set. Safe fix. Runs when phpunit is installed.
require-protected-setup
Changes the visibility of the setUp() and tearDown() functions of PHPUnit to protected, to match the PHPUnit TestCase.
Not in any set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
require-size
All PHPUnit test cases should have @small, @medium or @large annotation to enable run time limits.
Not in any set. Safe fix. Runs when phpunit is installed.
require-static-data-provider
Make PHPUnit data providers static.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.
require-strict-types-in-tests
Add declare(strict_types=1) to PHPUnit test class file
In the code-quality set. Safe fix. Runs when phpunit is installed.
require-string-assert-argument
Cast 2nd argument in assertStringContainsString() to a string if not yet
In the code-quality set. Safe fix. Runs when phpunit is installed.
require-test-annotation-style
Mark tests consistently: a test prefix or a @test annotation.
In the code-quality set. Unsafe fix: it can change behaviour. Runs when phpunit is installed.