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 InvalidClass * * @return void */ public function testStringCheckerPlugin() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__) . DIRECTORY_SEPARATOR, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, '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, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, ' "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, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, ' \Psalm\Checker\ProjectChecker::class . "::foo", ]; }' ); $this->analyzeFile($file_path, new Context()); } /** * @return void */ public function testEchoCheckerPluginWithJustHtml() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__) . DIRECTORY_SEPARATOR, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, '

This is a header

' ); $this->analyzeFile($file_path, new Context()); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage TypeCoercion * * @return void */ public function testEchoCheckerPluginWithUnescapedConcatenatedString() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__) . DIRECTORY_SEPARATOR, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, '' ); $this->analyzeFile($file_path, new Context()); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage TypeCoercion * * @return void */ public function testEchoCheckerPluginWithUnescapedString() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__) . DIRECTORY_SEPARATOR, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, '' ); $this->analyzeFile($file_path, new Context()); } /** * @return void */ public function testEchoCheckerPluginWithEscapedString() { $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__) . DIRECTORY_SEPARATOR, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, ' Some text ' ); $this->analyzeFile($file_path, new Context()); } /** @return void */ public function testInheritedHookHandlersAreCalled() { require_once __DIR__ . '/stubs/extending_plugin_entrypoint.php'; $this->project_checker = $this->getProjectCheckerWithConfig( TestConfig::loadFromXML( dirname(__DIR__) . DIRECTORY_SEPARATOR, ' ' ) ); $this->project_checker->config->initializePlugins($this->project_checker); $this->assertContains( 'ExtendingPlugin', $this->project_checker->config->after_function_checks ); } }