create(ParserFactory::PREFER_PHP7); } /** * @return void */ public function setUp() { $config = new TestConfig(); FileChecker::clearCache(); $this->project_checker = new \Psalm\Checker\ProjectChecker(); } /** * @return void */ public function testConstArray() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('string', (string) $context->vars_in_scope['$a']); } /** * @return void */ public function testConstFeatures() { $stmts = self::$parser->parse('f(); $e = C::SENTENCE; $f = TWO; $g = C::ONE_THIRD; '); $file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('int', (string) $context->vars_in_scope['$d']); $this->assertEquals('string', (string) $context->vars_in_scope['$e']); $this->assertEquals('int', (string) $context->vars_in_scope['$f']); $this->assertEquals('float|int', (string) $context->vars_in_scope['$g']); } /** * @return void */ public function testVariadic() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testVariadicArray() { $stmts = self::$parser->parse(' */ function f(int ...$a_list) { return array_map( /** * @return int */ function (int $a) { return $a + 1; }, $a_list ); } f(1); f(1, 2); f(1, 2, 3); '); $file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testArgumentUnpacking() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testExponentiation() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testConstantAliasInNamespace() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testConstantAliasInClass() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testFunctionAliasInNamespace() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } /** * @return void */ public function testFunctionAliasInClass() { $stmts = self::$parser->parse('project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } }