@@ -52,6 +52,29 @@ public function testRenameReferencesInTwoFiles(): void
5252 self ::assertCount (3 , $ edits ->toLocatedTextEdits (), 'Locates two references ' );
5353 }
5454
55+ /**
56+ * Tests that the definition is renamed on the original file as described
57+ * in the LSP spec. Note that we use the "Simple" file-to-class name
58+ * strategy which scans the contents of the destination file to get the
59+ * class name. Therefore, despite having to save the renamed file, we do
60+ * not add it to the InMemoryDocumentLocator to simulate the behavior when
61+ * using Composer that has no reference to the new file, only the old one.
62+ */
63+ public function testRenameReferencesToNewFile (): void
64+ {
65+ $ document1 = $ this ->createDocument ('One.php ' , '<?php class One{} ' );
66+ $ document2 = $ this ->createDocument ('Two.php ' , '<?php class Two{}; One::class; ' );
67+
68+ file_put_contents ($ document2 ->uri ()->path (), $ document2 ->__toString ());
69+ $ renamer = $ this ->createRenamer ([$ document1 ], [(new ClassRecord ('One ' ))->setType ('class ' )]);
70+
71+ $ edits = wait ($ renamer ->renameFile ($ document1 ->uri (), $ document2 ->uri ()));
72+
73+ self ::assertInstanceOf (LocatedTextEditsMap::class, $ edits );
74+ assert ($ edits instanceof LocatedTextEditsMap);
75+ self ::assertCount (1 , $ edits ->toLocatedTextEdits (), 'Locates one reference ' );
76+ }
77+
5578 /**
5679 * @param TextDocument[] $textDocuments
5780 * @param Record[] $records
0 commit comments