Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.

Commit 58478eb

Browse files
committed
update test to ensure refernces are sorted
1 parent d5c6c4d commit 58478eb

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

tests/LanguageServerReferenceFinder/Unit/Handler/ReferencesHandlerTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Phpactor\Extension\LanguageServerReferenceFinder\Tests\Unit\Handler;
44

55
use Phpactor\LanguageServerProtocol\Location as LspLocation;
6+
use Phpactor\LanguageServerProtocol\Position;
7+
use Phpactor\LanguageServerProtocol\Range;
68
use Phpactor\LanguageServerProtocol\ReferenceContext;
79
use Phpactor\LanguageServerProtocol\ReferencesRequest;
810
use Phpactor\Extension\LanguageServerBridge\Converter\LocationConverter;
@@ -21,6 +23,7 @@
2123
use Phpactor\TextDocument\ByteOffset;
2224
use Phpactor\TextDocument\Location;
2325
use Phpactor\TextDocument\TextDocumentBuilder;
26+
use Prophecy\Prophecy\ObjectProphecy;
2427

2528
class ReferencesHandlerTest extends TestCase
2629
{
@@ -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

0 commit comments

Comments
 (0)