phpstan/phpstan-phpunit
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
phpstan/phpstan | 1.11.1 | - | MIT | prod |
The phpstan/phpstan-phpunit package is an extension providing rules and extensions for PHPUnit which are used in PHPStan, a PHP static analysis tool. The package focuses on enhancing the utility of mock objects and their methods. For example, methods such as createMock()
, getMockForAbstractClass()
, and getMockFromWsdl()
return intersection types of the mock object and the mocked class, allowing usage of methods from both the mock object and the mocked class. The extension also makes getMock()
callable on MockBuilder
. The package is designed to improve the efficiency of PHP unit testing, providing utility to avoid undefined variable errors, specify types of expressions passed to various assert
methods, and more.
To use the phpstan/phpstan-phpunit package, you initially need to require it in Composer with the command composer require --dev phpstan/phpstan-phpunit
. After installation, you can leverage the capabilities of the package in your PHP unit testing code. Here's an example of how you might annotate mock objects in phpDocs with this package:
/**
* @return Foo&PHPUnit_Framework_MockObject_MockObject
*/
private function createFooMock()
{
return $this->createMock(Foo::class);
}
public function testSomething()
{
$fooMock = $this->createFooMock();
$fooMock->method('doFoo')->will($this->returnValue('test'));
$fooMock->doFoo();
}
If you also use phpstan/extension-installer
then you're all set up! During manual installation, if you want to include the package's extension and perform framework-specific checks in your project’s PHPStan config, use these lines of code:
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
The documentation for phpstan/phpstan-phpunit is primarily found on the GitHub page for the package itself located at phpstan-phpunit on GitHub. Furthermore, the details about PHPUnit can be found at PHPUnit and about PHPStan at PHPStan.