33namespace Phpactor \Extension \LanguageServerReferenceFinder \Tests \Unit \Handler ;
44
55use Phpactor \LanguageServerProtocol \Location as LspLocation ;
6+ use Phpactor \LanguageServerProtocol \Position ;
7+ use Phpactor \LanguageServerProtocol \Range ;
68use Phpactor \LanguageServerProtocol \ReferenceContext ;
79use Phpactor \LanguageServerProtocol \ReferencesRequest ;
810use Phpactor \Extension \LanguageServerBridge \Converter \LocationConverter ;
2123use Phpactor \TextDocument \ByteOffset ;
2224use Phpactor \TextDocument \Location ;
2325use Phpactor \TextDocument \TextDocumentBuilder ;
26+ use Prophecy \Prophecy \ObjectProphecy ;
2427
2528class ReferencesHandlerTest extends TestCase
2629{
2730 const EXAMPLE_URI = 'file:///test ' ;
2831 const EXAMPLE_TEXT = 'hello ' ;
2932
3033 /**
31- * @var ObjectProphecy| ReferenceFinder
34+ * @var ObjectProphecy< ReferenceFinder>
3235 */
3336 private $ finder ;
3437
3538 /**
36- * @var ObjectProphecy
39+ * @var ObjectProphecy<DefinitionLocator>
3740 */
3841 private $ locator ;
3942
@@ -51,14 +54,23 @@ public function testFindsReferences(): void
5154 ->build ()
5255 ;
5356
57+ $ document2 = TextDocumentBuilder::create (self ::EXAMPLE_TEXT )
58+ ->language ('php ' )
59+ ->uri (self ::EXAMPLE_URI .'2 ' )
60+ ->build ()
61+ ;
62+
5463 $ this ->finder ->findReferences (
5564 $ document ,
5665 ByteOffset::fromInt (0 )
5766 )->willYield ([
58- PotentialLocation::surely (new Location ($ document ->uri (), ByteOffset::fromInt (2 )))
67+ PotentialLocation::surely (new Location ($ document ->uri (), ByteOffset::fromInt (2 ))),
68+ PotentialLocation::surely (new Location ($ document2 ->uri (), ByteOffset::fromInt (3 ))),
69+ PotentialLocation::surely (new Location ($ document ->uri (), ByteOffset::fromInt (5 ))),
5970 ])->shouldBeCalled ();
6071
6172 $ tester = $ this ->createTester ();
73+ $ tester ->textDocument ()->open (self ::EXAMPLE_URI .'2 ' , self ::EXAMPLE_TEXT );
6274
6375 $ response = $ tester ->requestAndWait (ReferencesRequest::METHOD , [
6476 'textDocument ' => ProtocolFactory::textDocumentIdentifier (self ::EXAMPLE_URI ),
@@ -68,9 +80,20 @@ public function testFindsReferences(): void
6880
6981 $ locations = $ response ->result ;
7082 $ this ->assertIsArray ($ locations );
71- $ this ->assertCount (1 , $ locations );
72- $ lspLocation = reset ($ locations );
73- $ this ->assertInstanceOf (LspLocation::class, $ lspLocation );
83+ $ this ->assertEquals ([
84+ new LspLocation (
85+ (string ) $ document ->uri (),
86+ new Range (new Position (0 , 2 ), new Position (0 , 2 )),
87+ ),
88+ new LspLocation (
89+ (string ) $ document ->uri (),
90+ new Range (new Position (0 , 5 ), new Position (0 , 5 )),
91+ ),
92+ new LspLocation (
93+ (string ) $ document2 ->uri (),
94+ new Range (new Position (0 , 3 ), new Position (0 , 3 )),
95+ ),
96+ ], $ locations );
7497 }
7598
7699 public function testFindsReferencesIncludingDeclaration (): void
@@ -93,7 +116,7 @@ public function testFindsReferencesIncludingDeclaration(): void
93116 ByteOffset::fromInt (0 )
94117 )->willReturn (new DefinitionLocation ($ document ->uri (), ByteOffset::fromInt (2 )))->shouldBeCalled ();
95118
96- $ response = $ this ->createTester (true )->requestAndWait (ReferencesRequest::METHOD , [
119+ $ response = $ this ->createTester ()->requestAndWait (ReferencesRequest::METHOD , [
97120 'textDocument ' => ProtocolFactory::textDocumentIdentifier (self ::EXAMPLE_URI ),
98121 'position ' => ProtocolFactory::position (0 , 0 ),
99122 'context ' => new ReferenceContext (true ),
@@ -105,7 +128,7 @@ public function testFindsReferencesIncludingDeclaration(): void
105128 $ this ->assertInstanceOf (LspLocation::class, $ lspLocation );
106129 }
107130
108- public function testFindsReferencesIncludingDeclarationWhenDeclarationNotFound ()
131+ public function testFindsReferencesIncludingDeclarationWhenDeclarationNotFound (): void
109132 {
110133 $ document = TextDocumentBuilder::create (self ::EXAMPLE_TEXT )
111134 ->language ('php ' )
0 commit comments