1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00
psalm/tests/IssueSuppressionTest.php
LeSuisse f29826b958 Fully qualify constants and function calls (#1849)
This should give a small performance boost.
Part of #1837.

The change is enforced via phpcs and can be autofixed
with phpcbf.
2019-06-26 16:52:29 -04:00

143 lines
4.9 KiB
PHP

<?php
namespace Psalm\Tests;
use const DIRECTORY_SEPARATOR;
class IssueSuppressionTest extends TestCase
{
use Traits\ValidCodeAnalysisTestTrait;
use Traits\InvalidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
*/
public function providerValidCodeParse()
{
return [
'undefinedClass' => [
'<?php
class A {
/**
* @psalm-suppress UndefinedClass
* @psalm-suppress MixedMethodCall
* @psalm-suppress MissingReturnType
*/
public function b() {
B::fooFoo()->barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis();
}
}',
],
'undefinedClassOneLine' => [
'<?php
class A {
public function b(): void {
/**
* @psalm-suppress UndefinedClass
*/
new B();
}
}',
],
'undefinedClassOneLineInFile' => [
'<?php
/**
* @psalm-suppress UndefinedClass
*/
new B();',
],
'excludeIssue' => [
'<?php
fooFoo();',
'assertions' => [],
'error_levels' => ['UndefinedFunction'],
],
'crossClosureBoundariesOnFunction' => [
'<?php
/**
* @psalm-suppress MissingClosureParamType
* @psalm-suppress MissingClosureReturnType
*/
function foo(array $bar): array {
return array_map(
function ($value) {
return (string)$value;
},
$bar
);
}',
],
'crossClosureBoundariesOnReturn' => [
'<?php
function bar(array $bar): array {
/**
* @psalm-suppress MissingClosureParamType
* @psalm-suppress MissingClosureReturnType
*/
return array_map(
function ($value) {
return (string)$value;
},
$bar
);
}',
],
'suppressWithNewlineAfterComment' => [
'<?php
function foo() : void {
/**
* @psalm-suppress TooManyArguments
* here
*/
strlen("a", "b");
}'
],
'suppressUndefinedFunction' => [
'<?php
function verify_return_type(): DateTime {
/** @psalm-suppress UndefinedFunction */
unknown_function_call();
return new DateTime();
}',
],
];
}
/**
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
*/
public function providerInvalidCodeParse()
{
return [
'undefinedClassOneLineWithLineAfter' => [
'<?php
class A {
public function b() {
/**
* @psalm-suppress UndefinedClass
*/
new B();
new C();
}
}',
'error_message' => 'UndefinedClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:33 - Class or interface C',
],
'undefinedClassOneLineInFileAfter' => [
'<?php
/**
* @psalm-suppress UndefinedClass
*/
new B();
new C();',
'error_message' => 'UndefinedClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:6:25 - Class or interface C',
],
'missingParamTypeShouldntPreventUndefinedClassError' => [
'<?php
/** @psalm-suppress MissingParamType */
function foo($s = Foo::BAR) : void {}',
'error_message' => 'UndefinedClass',
],
];
}
}