Download the PHP package phpstan/phpstan-phpunit without Composer
On this page you can find all versions of the php package phpstan/phpstan-phpunit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpstan/phpstan-phpunit
More information about phpstan/phpstan-phpunit
Files in phpstan/phpstan-phpunit
Package phpstan-phpunit
Short Description PHPUnit extensions and rules for PHPStan
License MIT
Informations about the package phpstan-phpunit
PHPStan PHPUnit extensions and rules
This extension provides following features:
createMock()
,getMockForAbstractClass()
andgetMockFromWsdl()
methods return an intersection type (see the detailed explanation of intersection types) of the mock object and the mocked class so that both methods from the mock object (likeexpects
) and from the mocked class are available on the object.getMock()
called onMockBuilder
is also supported.- Interprets
Foo|PHPUnit_Framework_MockObject_MockObject
in phpDoc so that it results in an intersection type instead of a union type. - Defines early terminating method calls for the
PHPUnit\Framework\TestCase
class to prevent undefined variable errors. - Specifies types of expressions passed to various
assert
methods likeassertInstanceOf
,assertTrue
,assertInternalType
etc. - Combined with PHPStan's level 4, it points out always-true and always-false asserts like
assertTrue(true)
etc.
It also contains this strict framework-specific rules (can be enabled separately):
- Check that you are not using
assertSame()
withtrue
as expected value.assertTrue()
should be used instead. - Check that you are not using
assertSame()
withfalse
as expected value.assertFalse()
should be used instead. - Check that you are not using
assertSame()
withnull
as expected value.assertNull()
should be used instead. - Check that you are not using
assertSame()
withcount($variable)
as second parameter.assertCount($variable)
should be used instead.
How to document mock objects in phpDocs?
If you need to configure the mock even after you assign it to a property or return it from a method, you should add PHPUnit_Framework_MockObject_MockObject
to the phpDoc:
Please note that the correct syntax for intersection types is Foo&PHPUnit_Framework_MockObject_MockObject
. Foo|PHPUnit_Framework_MockObject_MockObject
is also supported, but only for ecosystem and legacy reasons.
If the mock is fully configured and only the methods of the mocked class are supposed to be called on the value, it's fine to typehint only the mocked class:
Installation
To use this extension, require it in Composer:
If you also install phpstan/extension-installer then you're all set!