PHP code example of phpstan / phpstan-phpunit
1. Go to this page and download the library: Download phpstan/phpstan-phpunit library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpstan / phpstan-phpunit example snippets
/**
* @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();
}
/** @var Foo */
private $foo;
protected function setUp()
{
$fooMock = $this->createMock(Foo::class);
$fooMock->method('doFoo')->will($this->returnValue('test'));
$this->foo = $fooMock;
}
public function testSomething()
{
$this->foo->doFoo();
// $this->foo->method() and expects() can no longer be called
}