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;
|
2017-01-02 21:31:18 +01:00
|
|
|
|
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
|
|
protected $project_checker;
|
2016-07-25 00:02:15 +02:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-07-25 00:02:15 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
FileChecker::clearCache();
|
2017-01-02 21:31:18 +01:00
|
|
|
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
2017-02-01 01:22:05 +01:00
|
|
|
$this->project_checker->setConfig(new TestConfig());
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
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
|
|
|
*/
|
2017-01-06 07:07:11 +01:00
|
|
|
public function b() {
|
2016-12-30 19:09:00 +01:00
|
|
|
B::fooFoo()->barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis();
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods();
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|
2016-12-14 18:28:38 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
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
|
2016-12-30 19:09:00 +01:00
|
|
|
fooFoo();
|
2016-12-14 18:28:38 +01:00
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods();
|
2016-12-14 18:28:38 +01:00
|
|
|
}
|
2016-07-25 00:02:15 +02:00
|
|
|
}
|