2016-07-25 00:02:15 +02:00
|
|
|
<?php
|
2016-07-26 00:37:44 +02:00
|
|
|
namespace Psalm\Tests;
|
2016-07-25 00:02:15 +02:00
|
|
|
|
|
|
|
use PhpParser\ParserFactory;
|
|
|
|
use PHPUnit_Framework_TestCase;
|
2016-11-02 07:29:00 +01:00
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Config;
|
2016-07-25 00:02:15 +02:00
|
|
|
|
|
|
|
class IssueSuppressionTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-12-14 18:55:23 +01:00
|
|
|
/** @var \PhpParser\Parser */
|
2016-11-02 07:29:00 +01:00
|
|
|
protected static $parser;
|
|
|
|
protected static $file_filter;
|
2016-07-25 00:02:15 +02:00
|
|
|
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-12-14 18:28:38 +01:00
|
|
|
$config = new TestConfig();
|
|
|
|
$config->throw_exception = true;
|
2016-11-02 07:29:00 +01:00
|
|
|
FileChecker::clearCache();
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUndefinedClass()
|
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
$stmts = self::$parser->parse('<?php
|
2016-07-25 00:02:15 +02:00
|
|
|
|
|
|
|
class A{
|
|
|
|
/**
|
2016-10-11 20:17:55 +02:00
|
|
|
* @psalm-suppress UndefinedClass
|
2016-10-15 19:10:05 +02:00
|
|
|
* @psalm-suppress MixedMethodCall
|
2016-11-11 23:13:24 +01:00
|
|
|
* @psalm-suppress MissingReturnType
|
2016-07-25 00:02:15 +02:00
|
|
|
*/
|
|
|
|
public function a() {
|
|
|
|
B::foo()->bar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $stmts);
|
2016-07-25 00:02:15 +02:00
|
|
|
$file_checker->check();
|
|
|
|
}
|
2016-12-14 18:28:38 +01:00
|
|
|
|
2016-12-30 02:07:42 +01:00
|
|
|
public function testExcludeIssue()
|
2016-12-14 18:28:38 +01:00
|
|
|
{
|
2016-12-30 02:07:42 +01:00
|
|
|
Config::getInstance()->setCustomErrorLevel('UndefinedFunction', Config::REPORT_SUPPRESS);
|
2016-12-14 18:28:38 +01:00
|
|
|
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
foo();
|
|
|
|
');
|
|
|
|
|
|
|
|
$file_checker = new FileChecker('somefile.php', $stmts);
|
|
|
|
$file_checker->check();
|
|
|
|
}
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|