Add starter files for PHPUnit Plugin

This commit is contained in:
Matthew Brown 2018-11-14 00:36:33 -05:00
commit fa76f65209
6 changed files with 221 additions and 0 deletions

3
.gitignore vendored Executable file
View File

@ -0,0 +1,3 @@
/vendor/
composer.lock
vendor

15
Plugin.php Executable file
View File

@ -0,0 +1,15 @@
<?php
namespace Psalm\PhpUnitPlugin;
use SimpleXMLElement;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
class Plugin implements PluginEntryPointInterface
{
/** @return void */
public function __invoke(RegistrationInterface $psalm, SimpleXMLElement $config = null)
{
$psalm->addStubFile(__DIR__ . '/stubs/TestCase.php');
}
}

37
composer.json Executable file
View File

@ -0,0 +1,37 @@
{
"name": "psalm/phpunit-plugin",
"description": "Psalm plugin for PHPUnit",
"type": "psalm-plugin",
"license": "MIT",
"authors": [
{
"name": "Matt Brown",
"email": "github@muglug.com"
}
],
"require": {
"vimeo/psalm": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^7.2",
"squizlabs/php_codesniffer": "^3.3"
},
"extra": {
"pluginClass": "Psalm\\PhpUnitPlugin\\Plugin"
},
"autoload": {
"psr-4": {
"Psalm\\PhpUnitPlugin\\": ["."]
}
},
"scripts" : {
"check": [
"@cs-check",
"@test",
"@analyze"
],
"analyze": "psalm",
"cs-check": "phpcs",
"cs-fix": "phpcbf"
}
}

30
phpcs.xml.dist Executable file
View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<ruleset name="invajo">
<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>
<!-- Paths to check -->
<file>Plugin.php</file>
<!-- inherit rules from: -->
<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="absoluteLineLimit" value="120"/><!-- even though psr-2 specifies it as soft-limit only -->
</properties>
</rule>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
</ruleset>

32
psalm.xml.dist Executable file
View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="." />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</PropertyNotSetInConstructor>
<TypeCoercion>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</TypeCoercion>
</issueHandlers>
</psalm>

104
stubs/TestCase.php Normal file
View File

@ -0,0 +1,104 @@
<?php
namespace PHPUnit\Framework;
use PHPUnit\Framework\MockObject\MockObject;
abstract class TestCase extends Assert implements Test, SelfDescribing
{
/**
* @template T
* @template-typeof T $class
* @param class-string $class
* @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 = '') {}
}