1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00

Fix code style and run PsalmTest only on PHP 7.1+

This commit is contained in:
Niklas Keller 2020-04-30 06:54:50 +02:00
parent 17e2c2344c
commit 1e58d53e4a
3 changed files with 15 additions and 12 deletions

View File

@ -9,7 +9,6 @@ use function Amp\Promise\wait;
*/ */
function accept(string $param) function accept(string $param)
{ {
} }
$coroutine = call(function (): \Generator { $coroutine = call(function (): \Generator {
@ -44,5 +43,3 @@ accept(wait(call(function (): \Generator {
accept(wait(call(function (): string { accept(wait(call(function (): string {
return 'foobar'; return 'foobar';
}))); })));

View File

@ -8,7 +8,6 @@ use function Amp\Promise\wait;
*/ */
function accept(string $param) function accept(string $param)
{ {
} }
$coroutine = coroutine(function (): \Generator { $coroutine = coroutine(function (): \Generator {
@ -19,5 +18,3 @@ $coroutine = coroutine(function (): \Generator {
// psalm-expect InvalidScalarArgument // psalm-expect InvalidScalarArgument
accept(wait($coroutine())); accept(wait($coroutine()));

View File

@ -6,24 +6,33 @@ use PHPUnit\Framework\TestCase;
class PsalmTest extends TestCase class PsalmTest extends TestCase
{ {
/**
* @requires PHP >= 7.1
*/
public function test() public function test()
{ {
$issues = \json_decode(\shell_exec('./vendor/bin/psalm --output-format=json --no-progress --config=psalm.examples.xml'), $issues = \json_decode(
true); \shell_exec('./vendor/bin/psalm --output-format=json --no-progress --config=psalm.examples.xml'),
true
);
foreach ($issues as $issue) { foreach ($issues as $issue) {
$file = \file_get_contents($issue['file_path']); $file = \file_get_contents($issue['file_path']);
$fileLines = \explode("\n", $file); $fileLines = \explode("\n", $file);
if (!\preg_match('(// psalm-expect (.*))', $fileLines[$issue['line_from'] - 2] ?? '', $match)) { if (!\preg_match('(// psalm-expect (.*))', $fileLines[$issue['line_from'] - 2] ?? '', $match)) {
$this->fail('Psalm reports an issue that isn\'t marked as expected: ' . \json_encode($issue, $this->fail('Psalm reports an issue that isn\'t marked as expected: ' . \json_encode(
\JSON_PRETTY_PRINT)); $issue,
\JSON_PRETTY_PRINT
));
} }
$expectedIssues = \array_map('trim', \explode(',', $match[1])); $expectedIssues = \array_map('trim', \explode(',', $match[1]));
if (!\in_array($issue['type'], $expectedIssues, true)) { if (!\in_array($issue['type'], $expectedIssues, true)) {
$this->fail('Psalm reports an issue that isn\'t marked as expected: ' . \json_encode($issue, $this->fail('Psalm reports an issue that isn\'t marked as expected: ' . \json_encode(
\JSON_PRETTY_PRINT)); $issue,
\JSON_PRETTY_PRINT
));
} }
} }