Put asserts in proper place

This commit is contained in:
Matthew Brown 2018-11-14 09:23:26 -05:00
parent fa76f65209
commit b49f07b34b
4 changed files with 98 additions and 89 deletions

View File

@ -10,6 +10,7 @@ class Plugin implements PluginEntryPointInterface
/** @return void */
public function __invoke(RegistrationInterface $psalm, SimpleXMLElement $config = null)
{
$psalm->addStubFile(__DIR__ . '/stubs/Assert.php');
$psalm->addStubFile(__DIR__ . '/stubs/TestCase.php');
}
}

View File

@ -17,7 +17,9 @@
"squizlabs/php_codesniffer": "^3.3"
},
"extra": {
"pluginClass": "Psalm\\PhpUnitPlugin\\Plugin"
"psalm": {
"pluginClass": "Psalm\\PhpUnitPlugin\\Plugin"
}
},
"autoload": {
"psr-4": {

94
stubs/Assert.php Normal file
View File

@ -0,0 +1,94 @@
<?php
namespace PHPUnit\Framework;
abstract class Assert
{
/**
* Asserts that a variable is of a given type.
*
* @param class-string $expected
* @param mixed $actual
* @param string $message
*
* @template T
* @template-typeof T $expected
* @psalm-assert T $actual
*/
public static function assertInstanceOf($expected, $actual, $message = '') {}
/**
* Asserts that a variable is of a given type.
*
* @param class-string $expected
* @param mixed $actual
* @param string $message
*
* @template T
* @template-typeof T $expected
* @psalm-assert !T $actual
*/
public static function assertNotInstanceOf($expected, $actual, $message = '') {}
/**
* Asserts that a condition is true.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert true $actual
*/
public static function assertTrue($condition, $message = '') {}
/**
* Asserts that a condition is not true.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert !true $actual
*/
public static function assertNotTrue($condition, $message = '') {}
/**
* Asserts that a condition is false.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert false $actual
*/
public static function assertFalse($condition, $message = '') {}
/**
* Asserts that a condition is not false.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert !false $actual
*/
public static function assertNotFalse($condition, $message = '') {}
/**
* Asserts that a variable is null.
*
* @param mixed $actual
* @param string $message
* @psalm-assert null $actual
*/
public static function assertNull($actual, $message = '') {}
/**
* Asserts that a variable is not null.
*
* @param mixed $actual
* @param string $message
* @psalm-assert !null $actual
*/
public static function assertNotNull($actual, $message = '') {}
}

View File

@ -13,92 +13,4 @@ abstract class TestCase extends Assert implements Test, SelfDescribing
* @return MockObject&T
*/
public function createMock($class) {}
/**
* Asserts that a variable is of a given type.
*
* @param class-string $expected
* @param mixed $actual
* @param string $message
*
* @template T
* @template-typeof T $expected
* @psalm-assert T $actual
*/
public static function assertInstanceOf($expected, $actual, $message = '') {}
/**
* Asserts that a variable is of a given type.
*
* @param class-string $expected
* @param mixed $actual
* @param string $message
*
* @template T
* @template-typeof T $expected
* @psalm-assert !T $actual
*/
public static function assertNotInstanceOf($expected, $actual, $message = '') {}
/**
* Asserts that a condition is true.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert true $actual
*/
public static function assertTrue($condition, $message = '') {}
/**
* Asserts that a condition is not true.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert !true $actual
*/
public static function assertNotTrue($condition, $message = '') {}
/**
* Asserts that a condition is false.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert false $actual
*/
public static function assertFalse($condition, $message = '') {}
/**
* Asserts that a condition is not false.
*
* @param bool $condition
* @param string $message
*
* @throws AssertionFailedError
* @psalm-assert !false $actual
*/
public static function assertNotFalse($condition, $message = '') {}
/**
* Asserts that a variable is null.
*
* @param mixed $actual
* @param string $message
* @psalm-assert null $actual
*/
public static function assertNull($actual, $message = '') {}
/**
* Asserts that a variable is not null.
*
* @param mixed $actual
* @param string $message
* @psalm-assert !null $actual
*/
public static function assertNotNull($actual, $message = '') {}
}