From a7872472be5bded0a3c622bb83b26a24e6388bac Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 31 Jan 2017 19:22:05 -0500 Subject: [PATCH] Add stubbing tests and modify config initialisation --- psalm.xml | 1 + tests/AnnotationTest.php | 7 +- tests/ArgTest.php | 7 +- tests/ArrayAccessTest.php | 2 +- tests/ArrayAssignmentTest.php | 2 +- tests/AssignmentTest.php | 7 +- tests/BinaryOperationTest.php | 2 +- tests/ClassScopeTest.php | 7 +- tests/ClassTest.php | 2 +- tests/ClosureTest.php | 7 +- tests/ConfigTest.php | 240 +++++++++++++++++++++++-------- tests/ConstantTest.php | 7 +- tests/ForTest.php | 7 +- tests/ForbiddenCodeTest.php | 7 +- tests/ForeachTest.php | 7 +- tests/FunctionCallTest.php | 2 +- tests/IncludeTest.php | 7 +- tests/InterfaceTest.php | 3 +- tests/IssueSuppressionTest.php | 3 +- tests/JsonOutputTest.php | 9 +- tests/ListTest.php | 7 +- tests/MethodCallTest.php | 2 +- tests/MethodMutationTest.php | 6 +- tests/MethodSignatureTest.php | 7 +- tests/NamespaceTest.php | 7 +- tests/Php40Test.php | 7 +- tests/Php55Test.php | 7 +- tests/Php56Test.php | 6 +- tests/Php70Test.php | 2 +- tests/Php71Test.php | 8 +- tests/PropertyTypeTest.php | 3 +- tests/ReturnTypeTest.php | 7 +- tests/ScopeTest.php | 7 +- tests/SwitchTypeTest.php | 7 +- tests/ToStringTest.php | 6 +- tests/TraitTest.php | 6 +- tests/TypeCombinationTest.php | 5 + tests/TypeParseTest.php | 4 + tests/TypeReconciliationTest.php | 12 +- tests/TypeTest.php | 8 +- tests/bootstrap.php | 1 + tests/stubs/logicexception.php | 8 ++ tests/stubs/systemclass.php | 19 +++ 43 files changed, 360 insertions(+), 128 deletions(-) create mode 100644 tests/stubs/logicexception.php create mode 100644 tests/stubs/systemclass.php diff --git a/psalm.xml b/psalm.xml index 753b3946e..ea1157dd8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -11,6 +11,7 @@ + diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index cce4d3001..0b59b8f6d 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -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); } /** diff --git a/tests/ArgTest.php b/tests/ArgTest.php index 549adbb1e..5403e7a43 100644 --- a/tests/ArgTest.php +++ b/tests/ArgTest.php @@ -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); } /** diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index d6bb7bd40..28da771de 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -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()); } /** diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index b6273c527..3471c1504 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -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()); } /** diff --git a/tests/AssignmentTest.php b/tests/AssignmentTest.php index db807a26d..e9998c202 100644 --- a/tests/AssignmentTest.php +++ b/tests/AssignmentTest.php @@ -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); } /** diff --git a/tests/BinaryOperationTest.php b/tests/BinaryOperationTest.php index b41dd83dc..a0822be09 100644 --- a/tests/BinaryOperationTest.php +++ b/tests/BinaryOperationTest.php @@ -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()); } /** diff --git a/tests/ClassScopeTest.php b/tests/ClassScopeTest.php index 9607fefb9..d79a87e56 100644 --- a/tests/ClassScopeTest.php +++ b/tests/ClassScopeTest.php @@ -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); } /** diff --git a/tests/ClassTest.php b/tests/ClassTest.php index 9b60a3690..a2e3d7ca1 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -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()); } /** diff --git a/tests/ClosureTest.php b/tests/ClosureTest.php index 640140e7f..3d1d98392 100644 --- a/tests/ClosureTest.php +++ b/tests/ClosureTest.php @@ -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); } /** diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 7595bdb5a..80e6f7023 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -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', ' - - - - -'); + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + + ' + ); $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', ' - - - - - - - -'); + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + + + + + ' + ); $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', ' - - - - - + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + + - - - -'); + + + + ' + ); $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', ' - - - - - + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + + - - - - - - - - - - -'); + + + + + + + + + + + ' + ); $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', ' - - - - + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + - - ' . $all_possible_handlers . ' - -'); + + ' . $all_possible_handlers . ' + + ' + ); } /** @@ -174,15 +205,104 @@ class ConfigTest extends PHPUnit_Framework_TestCase */ public function testImpossibleIssue() { - $config = Config::loadFromXML('psalm.xml', ' - - - - + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + - - - -'); + + + + ' + ); + } + + /** + * @expectedException \Psalm\Exception\ConfigException + * @expectedExceptionMessage Cannot resolve stubfile path + * @return void + */ + public function testNonexistentStubFile() + { + $config = Config::loadFromXML( + 'psalm.xml', + ' + + + + + + + + + ' + ); + } + + /** + * @return void + */ + public function testStubFile() + { + $this->project_checker->setConfig( + TestConfig::loadFromXML( + 'psalm.xml', + ' + + + + + + + + + ' + ) + ); + + $stmts = self::$parser->parse('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', + ' + + + + + + + + + ' + ) + ); + + $stmts = self::$parser->parse('project_checker, $stmts); + $context = new Context(); + $file_checker->visitAndAnalyzeMethods($context); } } diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index 4fd9243ef..39ed07b19 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -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); } /** diff --git a/tests/ForTest.php b/tests/ForTest.php index 6207b33dc..1434680d0 100644 --- a/tests/ForTest.php +++ b/tests/ForTest.php @@ -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); } /** diff --git a/tests/ForbiddenCodeTest.php b/tests/ForbiddenCodeTest.php index 9a021d9bc..bf6a1130e 100644 --- a/tests/ForbiddenCodeTest.php +++ b/tests/ForbiddenCodeTest.php @@ -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); } /** diff --git a/tests/ForeachTest.php b/tests/ForeachTest.php index 379c46d4d..e2a5f81bf 100644 --- a/tests/ForeachTest.php +++ b/tests/ForeachTest.php @@ -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); } /** diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 0178b92fb..da22f8555 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -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()); } /** diff --git a/tests/IncludeTest.php b/tests/IncludeTest.php index fa2884266..4f399c29f 100644 --- a/tests/IncludeTest.php +++ b/tests/IncludeTest.php @@ -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); } /** diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 393c3f660..108c2a991 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -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()); } /** diff --git a/tests/IssueSuppressionTest.php b/tests/IssueSuppressionTest.php index f1b5fc877..8fe404190 100644 --- a/tests/IssueSuppressionTest.php +++ b/tests/IssueSuppressionTest.php @@ -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()); } /** diff --git a/tests/JsonOutputTest.php b/tests/JsonOutputTest.php index fe835c381..aa203567c 100644 --- a/tests/JsonOutputTest.php +++ b/tests/JsonOutputTest.php @@ -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); } /** diff --git a/tests/ListTest.php b/tests/ListTest.php index b1b585bb6..942b1d553 100644 --- a/tests/ListTest.php +++ b/tests/ListTest.php @@ -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); } /** diff --git a/tests/MethodCallTest.php b/tests/MethodCallTest.php index a298c2642..7d4192154 100644 --- a/tests/MethodCallTest.php +++ b/tests/MethodCallTest.php @@ -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()); } /** diff --git a/tests/MethodMutationTest.php b/tests/MethodMutationTest.php index 3b801533d..b8f852d7c 100644 --- a/tests/MethodMutationTest.php +++ b/tests/MethodMutationTest.php @@ -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); } /** diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index b3a13471d..555d0a068 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -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); } /** diff --git a/tests/NamespaceTest.php b/tests/NamespaceTest.php index 87632923f..28b5cca4f 100644 --- a/tests/NamespaceTest.php +++ b/tests/NamespaceTest.php @@ -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); } /** diff --git a/tests/Php40Test.php b/tests/Php40Test.php index 81d4647ac..9029b2fa0 100644 --- a/tests/Php40Test.php +++ b/tests/Php40Test.php @@ -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); } /** diff --git a/tests/Php55Test.php b/tests/Php55Test.php index f48d82c3d..83ee11b69 100644 --- a/tests/Php55Test.php +++ b/tests/Php55Test.php @@ -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); } /** diff --git a/tests/Php56Test.php b/tests/Php56Test.php index dc71f9ef2..3a18e9712 100644 --- a/tests/Php56Test.php +++ b/tests/Php56Test.php @@ -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); } /** diff --git a/tests/Php70Test.php b/tests/Php70Test.php index 92c98d684..f6d4592df 100644 --- a/tests/Php70Test.php +++ b/tests/Php70Test.php @@ -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()); } /** diff --git a/tests/Php71Test.php b/tests/Php71Test.php index f2ca570ad..6fc027aae 100644 --- a/tests/Php71Test.php +++ b/tests/Php71Test.php @@ -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); } /** diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 8347448fa..dcbdaeca7 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -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()); } /** diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 748b66605..c2a0b7fb2 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -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); } /** diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index 819244aff..458958181 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -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); } /** diff --git a/tests/SwitchTypeTest.php b/tests/SwitchTypeTest.php index a9c415235..317792470 100644 --- a/tests/SwitchTypeTest.php +++ b/tests/SwitchTypeTest.php @@ -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); } /** diff --git a/tests/ToStringTest.php b/tests/ToStringTest.php index ce1f5de35..2de34ec34 100644 --- a/tests/ToStringTest.php +++ b/tests/ToStringTest.php @@ -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); } /** diff --git a/tests/TraitTest.php b/tests/TraitTest.php index 4849ccf06..503a0901d 100644 --- a/tests/TraitTest.php +++ b/tests/TraitTest.php @@ -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); } /** diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index b5e4d20fb..477a75067 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -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); } /** diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index b9cd5d8aa..36047689e 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -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(); } /** diff --git a/tests/TypeReconciliationTest.php b/tests/TypeReconciliationTest.php index 909e038e3..7f49a8d83 100644 --- a/tests/TypeReconciliationTest.php +++ b/tests/TypeReconciliationTest.php @@ -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(); } /** diff --git a/tests/TypeTest.php b/tests/TypeTest.php index cd41ecd60..da76497bb 100644 --- a/tests/TypeTest.php +++ b/tests/TypeTest.php @@ -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); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ec55bd438..55d15f200 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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) { diff --git a/tests/stubs/logicexception.php b/tests/stubs/logicexception.php new file mode 100644 index 000000000..9def7d8be --- /dev/null +++ b/tests/stubs/logicexception.php @@ -0,0 +1,8 @@ +