Improve mocking support

This commit is contained in:
Matthew Brown 2018-11-24 18:27:52 -05:00
parent ff427489f0
commit 0c8386711c
3 changed files with 47 additions and 2 deletions

View File

@ -12,5 +12,6 @@ class Plugin implements PluginEntryPointInterface
{
$psalm->addStubFile(__DIR__ . '/stubs/Assert.php');
$psalm->addStubFile(__DIR__ . '/stubs/TestCase.php');
$psalm->addStubFile(__DIR__ . '/stubs/MockBuilder.php');
}
}

33
stubs/MockBuilder.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace PHPUnit\Framework\MockObject;
use PHPUnit\Framework\TestCase;
/**
* @template T
*/
class MockBuilder
{
/**
* @template-typeof T $type
* @param TestCase $testCase
* @param class-string $type
*/
public function __construct(TestCase $testCase, $type) {}
/**
* Creates a mock object using a fluent interface.
*
* @return MockObject&T
*/
public function getMock() {}
/**
* Specifies the subset of methods to mock. Default is to mock none of them.
*
* @param array|null $methods
*
* @return static
*/
public function setMethods(array $methods = null) {}
}

View File

@ -1,8 +1,8 @@
<?php
namespace PHPUnit\Framework;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\MockBuilder;
abstract class TestCase extends Assert implements Test, SelfDescribing
{
@ -13,4 +13,15 @@ abstract class TestCase extends Assert implements Test, SelfDescribing
* @return MockObject&T
*/
public function createMock($class) {}
}
/**
* Returns a builder object to create mock objects using a fluent interface.
*
* @template T
* @template-typeof T $className
* @param class-string $className
*
* @return MockBuilder<T>
*/
public function getMockBuilder(string $className) {}
}