Merge pull request #4 from weirdan/prophecy-support

Prophecy support
This commit is contained in:
Matthew Brown 2018-12-08 17:55:26 -05:00 committed by GitHub
commit 059684417f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 13 deletions

View File

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

View File

@ -29,7 +29,6 @@
"scripts" : { "scripts" : {
"check": [ "check": [
"@cs-check", "@cs-check",
"@test",
"@analyze" "@analyze"
], ],
"analyze": "psalm", "analyze": "psalm",

View File

@ -9,6 +9,7 @@
<directory name="." /> <directory name="." />
<ignoreFiles> <ignoreFiles>
<directory name="vendor" /> <directory name="vendor" />
<directory name="stubs" />
</ignoreFiles> </ignoreFiles>
</projectFiles> </projectFiles>
@ -16,17 +17,5 @@
<LessSpecificReturnType errorLevel="info" /> <LessSpecificReturnType errorLevel="info" />
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</PropertyNotSetInConstructor>
<TypeCoercion>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</TypeCoercion>
</issueHandlers> </issueHandlers>
</psalm> </psalm>

26
stubs/Prophecy.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace Prophecy\Prophecy {
/** @template T */
class ObjectProphecy implements ProphecyInterface
{
/** @return T */
public function reveal() {}
}
class MethodProphecy
{
public function willReturn(...$values): self {}
}
}
namespace Prophecy {
use Prophecy\Argument\Token;
class Argument
{
/** @param callable():bool $callback */
public static function that(callable $callback): Token\CallbackToken {}
/** @param mixed ...$tokens */
public static function allOf(...$tokens): Token\LogicalAndToken {}
}
}

View File

@ -24,4 +24,12 @@ abstract class TestCase extends Assert implements Test, SelfDescribing
* @return MockBuilder<T> * @return MockBuilder<T>
*/ */
public function getMockBuilder(string $className) {} public function getMockBuilder(string $className) {}
/**
* @template T
* @template-typeof T $classOrInterface
* @param class-string $classOrInterface
* @return ObjectProphecy<T>
*/
public function prophesize($classOrInterface): ObjectProphecy {}
} }