2016-07-24 18:02:15 -04:00
|
|
|
<?php
|
2016-07-25 18:37:44 -04:00
|
|
|
namespace Psalm\Tests;
|
2016-07-24 18:02:15 -04:00
|
|
|
|
|
|
|
use PhpParser\ParserFactory;
|
|
|
|
use PHPUnit_Framework_TestCase;
|
2016-11-02 02:29:00 -04:00
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Config;
|
2016-07-24 18:02:15 -04:00
|
|
|
|
|
|
|
class IssueSuppressionTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-12-14 12:55:23 -05:00
|
|
|
/** @var \PhpParser\Parser */
|
2016-11-02 02:29:00 -04:00
|
|
|
protected static $parser;
|
2017-01-02 15:31:18 -05:00
|
|
|
|
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
|
|
protected $project_checker;
|
2016-07-24 18:02:15 -04:00
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-07-24 18:02:15 -04:00
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
2016-11-02 02:29:00 -04:00
|
|
|
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
2016-07-24 18:02:15 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-07-24 18:02:15 -04:00
|
|
|
public function setUp()
|
|
|
|
{
|
2016-11-02 02:29:00 -04:00
|
|
|
FileChecker::clearCache();
|
2017-01-02 15:31:18 -05:00
|
|
|
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
2017-01-31 19:22:05 -05:00
|
|
|
$this->project_checker->setConfig(new TestConfig());
|
2016-07-24 18:02:15 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-07-24 18:02:15 -04:00
|
|
|
public function testUndefinedClass()
|
|
|
|
{
|
2016-11-02 02:29:00 -04:00
|
|
|
$stmts = self::$parser->parse('<?php
|
2016-07-24 18:02:15 -04:00
|
|
|
|
|
|
|
class A{
|
|
|
|
/**
|
2016-10-11 14:17:55 -04:00
|
|
|
* @psalm-suppress UndefinedClass
|
2016-10-15 13:10:05 -04:00
|
|
|
* @psalm-suppress MixedMethodCall
|
2016-11-11 17:13:24 -05:00
|
|
|
* @psalm-suppress MissingReturnType
|
2016-07-24 18:02:15 -04:00
|
|
|
*/
|
2017-01-06 01:07:11 -05:00
|
|
|
public function b() {
|
2016-12-30 13:09:00 -05:00
|
|
|
B::fooFoo()->barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis();
|
2016-07-24 18:02:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
2017-01-02 15:31:18 -05:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2017-01-07 15:09:47 -05:00
|
|
|
$file_checker->visitAndAnalyzeMethods();
|
2016-07-24 18:02:15 -04:00
|
|
|
}
|
2016-12-14 12:28:38 -05:00
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-29 20:07:42 -05:00
|
|
|
public function testExcludeIssue()
|
2016-12-14 12:28:38 -05:00
|
|
|
{
|
2016-12-29 20:07:42 -05:00
|
|
|
Config::getInstance()->setCustomErrorLevel('UndefinedFunction', Config::REPORT_SUPPRESS);
|
2016-12-14 12:28:38 -05:00
|
|
|
|
|
|
|
$stmts = self::$parser->parse('<?php
|
2016-12-30 13:09:00 -05:00
|
|
|
fooFoo();
|
2016-12-14 12:28:38 -05:00
|
|
|
');
|
|
|
|
|
2017-01-02 15:31:18 -05:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2017-01-07 15:09:47 -05:00
|
|
|
$file_checker->visitAndAnalyzeMethods();
|
2016-12-14 12:28:38 -05:00
|
|
|
}
|
2016-07-24 18:02:15 -04:00
|
|
|
}
|