Added test infrastructure

- Added Codeception scaffolding
- Added travis config
- Added example test
This commit is contained in:
Bruce Weirdan 2019-02-09 08:59:23 +02:00
parent 1284e51d3c
commit 6e0f0643d6
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
11 changed files with 106 additions and 6 deletions

11
codeception.yml Normal file
View File

@ -0,0 +1,11 @@
namespace: Psalm\PhpUnitPlugin\Tests
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed

View File

@ -14,7 +14,9 @@
"vimeo/psalm": "^3.0 || dev-master" "vimeo/psalm": "^3.0 || dev-master"
}, },
"require-dev": { "require-dev": {
"squizlabs/php_codesniffer": "^3.3.1" "squizlabs/php_codesniffer": "^3.3.1",
"codeception/base": "^2.5",
"weirdan/codeception-psalm-module": "dev-master"
}, },
"extra": { "extra": {
"psalm": { "psalm": {
@ -26,13 +28,20 @@
"Psalm\\PhpUnitPlugin\\": ["."] "Psalm\\PhpUnitPlugin\\": ["."]
} }
}, },
"autoload-dev": {
"psr-4": {
"Psalm\\PhpUnitPlugin\\Tests\\": ["tests/_support"]
}
},
"scripts" : { "scripts" : {
"check": [ "check": [
"@cs-check", "@cs-check",
"@analyze" "@analyze",
"@test"
], ],
"analyze": "psalm", "analyze": "psalm",
"cs-check": "phpcs", "cs-check": "phpcs",
"cs-fix": "phpcbf" "cs-fix": "phpcbf",
"test": "codecept run -v"
} }
} }

View File

@ -10,12 +10,15 @@
<ignoreFiles> <ignoreFiles>
<directory name="vendor" /> <directory name="vendor" />
<directory name="stubs" /> <directory name="stubs" />
<directory name="tests/_support/_generated" />
</ignoreFiles> </ignoreFiles>
</projectFiles> </projectFiles>
<issueHandlers> <issueHandlers>
<LessSpecificReturnType errorLevel="info" /> <LessSpecificReturnType errorLevel="info" />
</issueHandlers> </issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm> </psalm>

0
tests/_data/.gitkeep Normal file
View File

2
tests/_output/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

2
tests/_run/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,26 @@
<?php
namespace Psalm\PhpUnitPlugin\Tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}

View File

@ -0,0 +1,10 @@
<?php
namespace Psalm\PhpUnitPlugin\Tests\Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}

2
tests/_support/_generated/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,7 @@
actor: AcceptanceTester
modules:
enabled:
- Cli
- Filesystem
- \Weirdan\Codeception\Psalm\Module
- \Psalm\PhpUnitPlugin\Tests\Helper\Acceptance

View File

@ -0,0 +1,28 @@
Feature: Assert
In order to use PHPUnit safely
As a Psalm user
I need Psalm to typecheck asserts
Background:
Given I have the following code preamble
"""
<?php
namespace NS;
use PHPUnit\Framework\Assert;
"""
Scenario: Asserting instanceof
Given I have the following code
"""
function f(): \Exception {
return rand(0,1) ? new \RuntimeException : new \InvalidArgumentException;
}
function acceptsRuntimeException(\RuntimeException $_e): void {}
$e = f();
Assert::assertInstanceOf(\RuntimeException::class, $e);
acceptsRuntimeException($e);
"""
When I run Psalm
Then I see no errors