file_provider = new FakeFileProvider(); } /** * @dataProvider providerValidCodeParse * @param array $properties_to_move */ public function testValidCode( string $input_code, string $output_code, array $properties_to_move, ): void { $test_name = $this->getTestName(); if (str_contains($test_name, 'SKIPPED-')) { $this->markTestSkipped('Skipped due to a bug.'); } $config = new TestConfig(); $this->project_analyzer = new ProjectAnalyzer( $config, new Providers( $this->file_provider, new 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($properties_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(): array { return [ 'moveSimpleStaticProperty' => [ 'input' => ' */ public static $foo; } class B { public static function bar() : void { foreach (A::$foo as $f) {} } }', 'output' => ' */ public static $fooBar; }', 'migrations' => [ 'Ns\A::$foo' => 'Ns\B::$fooBar', ], ], 'renameInstanceProperty' => [ 'input' => 'foo; $a->foo = 10; }', 'output' => 'fooBar; $a->fooBar = 10; }', 'migrations' => [ 'Ns\A::$foo' => 'Ns\A::$fooBar', ], ], 'renameStaticProperty' => [ 'input' => ' ' [ 'Ns\A::$foo' => 'Ns\A::$fooBar', ], ], 'moveStaticProperty' => [ 'input' => ' ' [ 'Ns\A::$foo' => 'Ns\B::$fooBar', ], ], ]; } }