mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
97 lines
2.4 KiB
PHP
97 lines
2.4 KiB
PHP
<?php
|
|
namespace Psalm\Tests;
|
|
|
|
use Psalm\Checker\FileChecker;
|
|
use Psalm\Config;
|
|
use Psalm\Context;
|
|
|
|
class PluginTest extends TestCase
|
|
{
|
|
/** @var TestConfig */
|
|
protected static $config;
|
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
protected $project_checker;
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public static function setUpBeforeClass()
|
|
{
|
|
self::$config = new TestConfig();
|
|
|
|
if (!defined('PSALM_VERSION')) {
|
|
define('PSALM_VERSION', '2.0.0');
|
|
}
|
|
|
|
if (!defined('PHP_PARSER_VERSION')) {
|
|
define('PHP_PARSER_VERSION', '4.0.0');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function setUp()
|
|
{
|
|
FileChecker::clearCache();
|
|
$this->file_provider = new Provider\FakeFileProvider();
|
|
}
|
|
|
|
/**
|
|
* @param Config $config
|
|
*
|
|
* @return \Psalm\Checker\ProjectChecker
|
|
*/
|
|
private function getProjectCheckerWithConfig(Config $config)
|
|
{
|
|
return new \Psalm\Checker\ProjectChecker(
|
|
$config,
|
|
new \Psalm\Provider\Providers(
|
|
$this->file_provider,
|
|
new Provider\FakeParserCacheProvider()
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Psalm\Exception\CodeException
|
|
* @expectedExceptionMessage UndefinedMethod
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testStringCheckerPluginWithClassConstantConcat()
|
|
{
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
TestConfig::loadFromXML(
|
|
dirname(__DIR__) . DIRECTORY_SEPARATOR,
|
|
'<?xml version="1.0"?>
|
|
<psalm>
|
|
<projectFiles>
|
|
<directory name="src" />
|
|
</projectFiles>
|
|
<plugins>
|
|
<plugin filename="examples/StringChecker.php" />
|
|
</plugins>
|
|
</psalm>'
|
|
)
|
|
);
|
|
|
|
$this->project_checker->config->initializePlugins($this->project_checker);
|
|
|
|
$file_path = getcwd() . '/src/somefile.php';
|
|
|
|
$this->addFile(
|
|
$file_path,
|
|
'<?php
|
|
class A {
|
|
const C = [
|
|
"foo" => \Psalm\Checker\ProjectChecker::class . "::foo",
|
|
];
|
|
}'
|
|
);
|
|
|
|
$this->analyzeFile($file_path, new Context());
|
|
}
|
|
}
|