1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Move plugin tests into new file

This commit is contained in:
Brown 2018-10-29 11:41:02 -04:00
parent 0d7661dd3f
commit 05d1ce6dcd
2 changed files with 96 additions and 116 deletions

View File

@ -562,122 +562,6 @@ class ConfigTest extends TestCase
$this->analyzeFile($file_path, new Context());
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage InvalidClass
*
* @return void
*/
public function testStringCheckerPlugin()
{
$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
$a = "Psalm\Checker\ProjectChecker";'
);
$this->analyzeFile($file_path, new Context());
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage InvalidClass
*
* @return void
*/
public function testStringCheckerPluginWithClassConstant()
{
$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",
];
}'
);
$this->analyzeFile($file_path, new Context());
}
/**
* @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());
}
/**
* @return void
*/

96
tests/PluginTest.php Normal file
View File

@ -0,0 +1,96 @@
<?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());
}
}