file_provider = new FakeFileProvider(); } /** * @dataProvider providerValidCodeParse * @param array $constants_to_move */ public function testValidCode( string $input_code, string $output_code, array $constants_to_move, ): void { $test_name = $this->getTestName(); if (strpos($test_name, 'SKIPPED-') !== false) { $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($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(): array { return [ 'renameEmptyClass' => [ 'input' => ' ' [ 'Ns\A' => 'Ns\B', ], ], 'renameEmptyClassWithSpacesInDocblock' => [ 'input' => ' ' [ 'Ns\A' => 'Ns\B', ], ], 'renameClassWithInstanceMethod' => [ 'input' => 'foo($a, $a); }', 'output' => 'foo($a, $a); }', 'migrations' => [ 'Ns\A' => 'Ns\B', ], ], 'renameClassWithStaticMethod' => [ 'input' => ' ' [ 'Ns\A' => 'Ns\B', ], ], 'renameClassWithInstanceProperty' => [ 'input' => ' ' [ 'Ns\A' => 'Ns\B', ], ], 'renameClassWithStaticProperty' => [ 'input' => ' ' [ 'Ns\A' => 'Ns\B', ], ], 'moveClassIntoNamespace' => [ 'input' => ' $a * @throws RunTimeException */ public function foo(ArrayObject $a) : Exception { foreach ($a as $b) { $b->bar(); } try { // something } catch (InvalidArgumentException $e) { } echo \A::class; echo __CLASS__; echo self::class; ArrayObject::foo(); return new Exception("bad"); } public function bar() : void {} }', 'output' => ' $a * @throws \RunTimeException */ public function foo(\ArrayObject $a) : Exception { foreach ($a as $b) { $b->bar(); } try { // something } catch (\InvalidArgumentException $e) { } echo B::class; echo B::class; echo self::class; \ArrayObject::foo(); return new Exception("bad"); } public function bar() : void {} }', 'migrations' => [ 'A' => 'Foo\Bar\Baz\B', ], ], 'moveClassDeeperIntoNamespaceAdjustUseWithoutAlias' => [ 'input' => ' ' [ 'Bar\Bat' => 'Bar\Baz\Bahh', ], ], 'moveClassesIntoNamespace' => [ 'input' => ' ' [ 'Foo\A' => 'Bar\Baz\A', 'Foo\B' => 'Bar\Baz\B', ], ], 'moveClassesIntoNamespaceWithoutAlias' => [ 'input' => ' ' [ 'Foo\A' => 'Bar\Baz\A', 'Foo\B' => 'Bar\Baz\B', ], ], 'moveClassDeeperIntoNamespaceAdjustUseWithAlias' => [ 'input' => ' ' [ 'Bar\Bat' => 'Bar\Baz\Bahh', ], ], 'moveClassDeeperIntoNamespaceDontAdjustGroupUse' => [ 'input' => ' ' [ 'Bar\Bat' => 'Bar\Baz\Bahh', ], ], 'moveClassBewareOfPropertyNotSetInConstructorCheck' => [ 'input' => 'property1 = ""; } } } namespace Foo { class Hello extends Base {} }', 'output' => 'property1 = ""; } } } namespace Foo\Bar { class Hello extends \Foo\Base {} }', 'migrations' => [ 'Foo\Hello' => 'Foo\Bar\Hello', ], ], 'renamesAllStaticPropReferences' => [ 'input' => ' ' [ 'Foo\Bar' => 'Zoo\Baz', ], ], ]; } }