Merge pull request #9 from weirdan/tests

Testing infrastructure
This commit is contained in:
Bruce Weirdan 2019-02-11 05:26:15 +02:00 committed by GitHub
commit 34164fbbb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 127 additions and 6 deletions

21
.travis.yml Normal file
View File

@ -0,0 +1,21 @@
language: php
php:
- 7.3
before_install:
- phpenv config-rm xdebug.ini || true
install:
- composer install
- if [[ "$DEPS" = 'high' ]]; then travis_retry composer $DEFAULT_COMPOSER_FLAGS update; fi
- if [[ "$DEPS" = 'low' ]]; then travis_retry composer $DEFAULT_COMPOSER_FLAGS --prefer-lowest --prefer-stable update; fi
- if [[ "$DEPS" = 'stable' ]]; then travis_retry composer $DEFAULT_COMPOSER_FLAGS --prefer-stable update; fi
script: composer check
env:
matrix:
- DEPS="low"
- DEPS="high"
- DEPS="stable"
global:
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-suggest"

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

View File

@ -9,13 +9,16 @@
<directory name="." />
<ignoreFiles>
<directory name="vendor" />
<directory name="stubs" />
<directory name="stubs" />
<directory name="tests/_support" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
</issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</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