file_provider = new Provider\FakeFileProvider(); } /** * @param Config $config * * @return \Psalm\Checker\ProjectChecker */ private function getProjectCheckerWithConfig(Config $config) { $project_checker = new \Psalm\Checker\ProjectChecker( $config, new \Psalm\Provider\Providers( $this->file_provider, new Provider\FakeParserCacheProvider() ) ); $config->visitComposerAutoloadFiles($project_checker, false); return $project_checker; } /** * @expectedException \Psalm\Exception\ConfigException * @expectedExceptionMessage Cannot resolve stubfile path * * @return void */ public function testNonexistentStubFile() { $this->project_checker = $this->getProjectCheckerWithConfig( Config::loadFromXML( dirname(__DIR__), ' ' ) ); } /** * @return void */ public function testStubFile() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'foo(5, "hello"); $c = SystemClass::bar(5, "hello");' ); $this->analyzeFile($file_path, new Context()); } /** * @return void */ public function testNamespacedStubClass() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'foo(5, "hello"); $c = Foo\SystemClass::bar(5, "hello"); echo Foo\BAR;' ); $this->analyzeFile($file_path, new Context()); } /** * @return void */ public function testStubFunction() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testPolyfilledFunction() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testStubFunctionWithFunctionExists() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testNamespacedStubFunctionWithFunctionExists() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage UndefinedFunction - /src/somefile.php:2 - Function barBar does not exist * * @return void */ public function testNoStubFunction() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testNamespacedStubFunction() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testConditionalNamespacedStubFunction() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testStubFileWithExistingClassDefinition() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } /** * @return void */ public function testStubFileWithPartialClassDefinitionWithMoreMethods() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'foo(A::class); (new PartiallyStubbedClass())->bar(5);' ); $this->analyzeFile($file_path, new Context()); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage TypeCoercion * * @return void */ public function testStubFileWithPartialClassDefinitionWithCoercion() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'foo("dasda");' ); $this->analyzeFile($file_path, new Context()); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage InvalidReturnStatement * * @return void */ public function testStubFileWithPartialClassDefinitionGeneralReturnType() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } }