1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Add stubbing tests and modify config initialisation

This commit is contained in:
Matt Brown 2017-01-31 19:22:05 -05:00
parent 004fd42062
commit a7872472be
43 changed files with 360 additions and 128 deletions

View File

@ -11,6 +11,7 @@
<directory name="tests" />
<ignoreFiles>
<file name="src/Psalm/CallMap.php" />
<directory name="tests/stubs" />
</ignoreFiles>
</projectFiles>

View File

@ -12,6 +12,9 @@ class AnnotationTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class AnnotationTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class AnnotationTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class ArgTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ArgTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ArgTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -28,9 +28,9 @@ class ArrayAccessTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -29,9 +29,9 @@ class ArrayAssignmentTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
\Psalm\Checker\FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -12,6 +12,9 @@ class AssignmentTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class AssignmentTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class AssignmentTest extends PHPUnit_Framework_TestCase
{
\Psalm\Checker\FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -30,7 +30,7 @@ class BinaryOperationTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$config = new TestConfig();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -12,6 +12,9 @@ class ClassScopeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ClassScopeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ClassScopeTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -28,9 +28,9 @@ class ClassTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -12,6 +12,9 @@ class ClosureTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ClosureTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ClosureTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -5,12 +5,28 @@ use PhpParser\ParserFactory;
use PHPUnit_Framework_TestCase;
use Psalm\Checker\FileChecker;
use Psalm\Config;
use Psalm\Context;
class ConfigTest extends PHPUnit_Framework_TestCase
{
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
/**
* @return void
*/
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
* @return void
*/
@ -52,12 +68,15 @@ class ConfigTest extends PHPUnit_Framework_TestCase
*/
public function testBarebonesConfig()
{
$config = Config::loadFromXML('psalm.xml', '<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
</psalm>');
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
</psalm>'
);
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php')));
@ -68,15 +87,18 @@ class ConfigTest extends PHPUnit_Framework_TestCase
*/
public function testIgnoreProjectDirectory()
{
$config = Config::loadFromXML('psalm.xml', '<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="src/Psalm/Checker" />
</ignoreFiles>
</projectFiles>
</psalm>');
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="src/Psalm/Checker" />
</ignoreFiles>
</projectFiles>
</psalm>'
);
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
$this->assertFalse($config->isInProjectDirs(realpath('src/Psalm/Checker/FileChecker.php')));
@ -88,17 +110,20 @@ class ConfigTest extends PHPUnit_Framework_TestCase
*/
public function testIssueHandler()
{
$config = Config::loadFromXML('psalm.xml', '<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
<issueHandlers>
<MissingReturnType errorLevel="suppress" />
</issueHandlers>
</psalm>');
<issueHandlers>
<MissingReturnType errorLevel="suppress" />
</issueHandlers>
</psalm>'
);
$this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php')));
$this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
@ -109,24 +134,27 @@ class ConfigTest extends PHPUnit_Framework_TestCase
*/
public function testIssueHandlerWithCustomErrorLevels()
{
$config = Config::loadFromXML('psalm.xml', '<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</projectFiles>
<issueHandlers>
<MissingReturnType errorLevel="info">
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
<errorLevel type="error">
<directory name="src/Psalm/Checker" />
</errorLevel>
</MissingReturnType>
</issueHandlers>
</psalm>');
<issueHandlers>
<MissingReturnType errorLevel="info">
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
<errorLevel type="error">
<directory name="src/Psalm/Checker" />
</errorLevel>
</MissingReturnType>
</issueHandlers>
</psalm>'
);
$this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php')));
$this->assertFalse($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
@ -155,16 +183,19 @@ class ConfigTest extends PHPUnit_Framework_TestCase
)
);
$config = Config::loadFromXML('psalm.xml', '<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<issueHandlers>
' . $all_possible_handlers . '
</issueHandlers>
</psalm>');
<issueHandlers>
' . $all_possible_handlers . '
</issueHandlers>
</psalm>'
);
}
/**
@ -174,15 +205,104 @@ class ConfigTest extends PHPUnit_Framework_TestCase
*/
public function testImpossibleIssue()
{
$config = Config::loadFromXML('psalm.xml', '<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<issueHandlers>
<ImpossibleIssue errorLevel="suppress" />
</issueHandlers>
</psalm>');
<issueHandlers>
<ImpossibleIssue errorLevel="suppress" />
</issueHandlers>
</psalm>'
);
}
/**
* @expectedException \Psalm\Exception\ConfigException
* @expectedExceptionMessage Cannot resolve stubfile path
* @return void
*/
public function testNonexistentStubFile()
{
$config = Config::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<stubs>
<file name="stubs/invalidfile.php" />
</stubs>
</psalm>'
);
}
/**
* @return void
*/
public function testStubFile()
{
$this->project_checker->setConfig(
TestConfig::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<stubs>
<file name="tests/stubs/systemclass.php" />
</stubs>
</psalm>'
)
);
$stmts = self::$parser->parse('<?php
$a = new SystemClass();
echo SystemClass::HELLO;
$b = $a->foo(5, "hello");
$c = SystemClass::bar(5, "hello");
');
$file_checker = new FileChecker(getcwd() . '/src/somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testStubFileWithExistingClassDefinition()
{
$this->project_checker->setConfig(
TestConfig::loadFromXML(
'psalm.xml',
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<stubs>
<file name="tests/stubs/logicexception.php" />
</stubs>
</psalm>'
)
);
$stmts = self::$parser->parse('<?php
$a = new LogicException("bad");
');
$file_checker = new FileChecker(getcwd() . '/src/somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
}

View File

@ -12,6 +12,9 @@ class ConstantTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ConstantTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ConstantTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class ForTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ForTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ForTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class ForbiddenCodeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ForbiddenCodeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ForbiddenCodeTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class ForeachTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ForeachTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ForeachTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -28,9 +28,9 @@ class FunctionCallTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -11,6 +11,9 @@ class IncludeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -20,6 +23,7 @@ class IncludeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -27,10 +31,9 @@ class IncludeTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
$config->throw_exception = true;
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -21,8 +21,6 @@ class InterfaceTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
}
/**
@ -32,6 +30,7 @@ class InterfaceTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -27,10 +27,9 @@ class IssueSuppressionTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
$config->throw_exception = true;
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -23,10 +23,6 @@ class JsonOutputTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
$config->throw_exception = false;
$config->stop_on_first_error = false;
}
/**
@ -36,6 +32,11 @@ class JsonOutputTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$config = new TestConfig();
$config->throw_exception = false;
$config->stop_on_first_error = false;
$this->project_checker->setConfig($config);
}
/**

View File

@ -12,6 +12,9 @@ class ListTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ListTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ListTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -28,9 +28,9 @@ class MethodCallTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -13,6 +13,9 @@ class MethodMutationTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -22,6 +25,7 @@ class MethodMutationTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -29,9 +33,9 @@ class MethodMutationTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class MethodSignatureTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class MethodSignatureTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class MethodSignatureTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class NamespaceTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class NamespaceTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class NamespaceTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class Php40Test extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class Php40Test extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class Php40Test extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class Php55Test extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class Php55Test extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class Php55Test extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class Php56Test extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,6 +24,7 @@ class Php56Test extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -28,9 +32,9 @@ class Php56Test extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -28,9 +28,9 @@ class Php70Test extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -12,6 +12,9 @@ class Php71Test extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,6 +24,7 @@ class Php71Test extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -28,11 +32,9 @@ class Php71Test extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
$config->use_docblock_types = true;
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -28,10 +28,9 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
$config->throw_exception = true;
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(new TestConfig());
}
/**

View File

@ -12,6 +12,9 @@ class ReturnTypeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ReturnTypeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ReturnTypeTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class ScopeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,8 +24,7 @@ class ScopeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -32,6 +34,7 @@ class ScopeTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -14,6 +14,9 @@ class SwitchTypeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -23,8 +26,7 @@ class SwitchTypeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -34,6 +36,7 @@ class SwitchTypeTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class ToStringTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,6 +24,7 @@ class ToStringTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -28,9 +32,9 @@ class ToStringTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -12,6 +12,9 @@ class TraitTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,6 +24,7 @@ class TraitTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -28,9 +32,9 @@ class TraitTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -11,6 +11,9 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -20,6 +23,7 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**
@ -29,6 +33,7 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -10,6 +10,9 @@ class TypeParseTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -19,6 +22,7 @@ class TypeParseTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$config = new TestConfig();
}
/**

View File

@ -16,6 +16,9 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -28,8 +31,7 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
self::$config = new TestConfig();
}
/**
@ -38,12 +40,12 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
public function setUp()
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker = new ProjectChecker();
$this->project_checker->setConfig(self::$config);
$this->file_checker = new FileChecker('somefile.php', $this->project_checker);
$this->file_checker->context = new Context();
$this->project_checker = new ProjectChecker();
}
/**

View File

@ -12,6 +12,9 @@ class TypeTest extends PHPUnit_Framework_TestCase
/** @var \PhpParser\Parser */
protected static $parser;
/** @var TestConfig */
protected static $config;
/** @var \Psalm\Checker\ProjectChecker */
protected $project_checker;
@ -21,9 +24,7 @@ class TypeTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
$config->throw_exception = true;
self::$config = new TestConfig();
}
/**
@ -33,6 +34,7 @@ class TypeTest extends PHPUnit_Framework_TestCase
{
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
$this->project_checker->setConfig(self::$config);
}
/**

View File

@ -2,6 +2,7 @@
ini_set('display_startup_errors', 1);
ini_set('html_errors', 1);
ini_set('memory_limit', '-1');
error_reporting(E_ALL);
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {

View File

@ -0,0 +1,8 @@
<?php
class LogicException extends Exception {
/**
* @param int $a
*/
public function __construct($a) {}
}

View File

@ -0,0 +1,19 @@
<?php
class SystemClass {
const HELLO = 'hello';
/**
* @param int $a
* @param string $b
* @return string
*/
public function foo($a, $b) {}
/**
* @param int $a
* @param string $b
* @return string
*/
public static function bar($a, $b) {}
}