file_provider = new Provider\FakeFileProvider(); } /** * @dataProvider providerValidCodeParse * * @param string $input_code * @param string $output_code * @param array $constants_to_move * @param array $call_transforms * * @return void */ public function testValidCode( string $input_code, string $output_code, array $constants_to_move ) { $test_name = $this->getTestName(); if (strpos($test_name, 'SKIPPED-') !== false) { $this->markTestSkipped('Skipped due to a bug.'); } $config = new TestConfig(); $this->project_analyzer = new \Psalm\Internal\Analyzer\ProjectAnalyzer( $config, new \Psalm\Internal\Provider\Providers( $this->file_provider, new Provider\FakeParserCacheProvider() ) ); $context = new Context(); $file_path = self::$src_dir_path . 'somefile.php'; $this->addFile( $file_path, $input_code ); $codebase = $this->project_analyzer->getCodebase(); $this->project_analyzer->refactorCodeAfterCompletion($constants_to_move); $this->analyzeFile($file_path, $context); $this->project_analyzer->prepareMigration(); $codebase->analyzer->updateFile($file_path, false); $this->project_analyzer->migrateCode(); $this->assertSame($output_code, $codebase->getFileContents($file_path)); } /** * @return array}> */ public function providerValidCodeParse() { return [ 'renameEmptyClass' => [ ' 'Ns\B', ] ], 'renameClassWithInstanceMethod' => [ 'foo($a, $a); }', 'foo($a, $a); }', [ 'Ns\A' => 'Ns\B', ] ], 'renameClassWithStaticMethod' => [ ' 'Ns\B', ] ], 'renameClassWithInstanceProperty' => [ ' 'Ns\B', ] ], 'renameClassWithStaticProperty' => [ ' 'Ns\B', ] ], 'moveClassIntoNamespace' => [ ' $a */ public function foo(ArrayObject $a) : Exception { foreach ($a as $b) { $b->bar(); } echo \A::class; ArrayObject::foo(); return new Exception("bad"); } public function bar() : void {} }', ' $a */ public function foo(\ArrayObject $a) : Exception { foreach ($a as $b) { $b->bar(); } echo self::class; \ArrayObject::foo(); return new Exception("bad"); } public function bar() : void {} }', [ 'A' => 'Foo\Bar\Baz\B', ] ], 'moveClassDeeperIntoNamespace' => [ ' $a */ public function foo(ArrayObject $a) : Exception { foreach ($a as $b) { $b->bar(); } return new Exception("bad"); } public function bar() : void {} }', ' $a */ public function foo(ArrayObject $a) : Exception { foreach ($a as $b) { $b->bar(); } return new Exception("bad"); } public function bar() : void {} }', [ 'Foo\A' => 'Foo\Bar\Baz\B', ] ], ]; } }