Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Extension/ContextMenu/Handler/ContextMenuHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private function actionSelectionAction(Symbol $symbol, $symbolMenu, array $argum
self::NAME,
[
self::PARAMETER_SOURCE => $arguments[self::PARAMETER_SOURCE],
self::PARAMETER_OFFSET => $symbol->position()->start(),
self::PARAMETER_OFFSET => $arguments[self::PARAMETER_OFFSET],
self::PARAMETER_CURRENT_PATH => $arguments[self::PARAMETER_CURRENT_PATH],
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ContextMenuHandlerTest extends HandlerTestCase
{
const VARIABLE_ACTION = 'do_something';
const SOURCE = '<?php $hello = "world"; echo $hello;';
const FOUND_OFFSET = 10;
const ORIGINAL_OFFSET = 8;

/**
* @var Reflector
Expand Down Expand Up @@ -110,7 +112,7 @@ public function testReturnMenu()
'/hello.php',
'<?php $hello = "world"; echo $hello;'
);
$offset = ByteOffset::fromInt(8);
$offset = ByteOffset::fromInt(self::ORIGINAL_OFFSET);

$this->offsetFinder->find($source, $offset)
->willReturn($offset);
Expand All @@ -126,6 +128,36 @@ public function testReturnMenu()
$this->assertEquals(ContextMenuHandler::NAME, $action->callbackAction()->name());
}

public function testReturnMenuWithOriginalOffset()
{
$this->menu = [
Symbol::VARIABLE => [
'action' => self::VARIABLE_ACTION,
'parameters' => [
'one' => 1,
],
]
];

$source = SourceCode::fromPathAndString(
'/hello.php',
'<?php $hello = "world"; echo $hello;'
);
$offset = ByteOffset::fromInt(self::ORIGINAL_OFFSET);

$this->offsetFinder->find($source, $offset)
->willReturn(ByteOffset::fromInt(self::FOUND_OFFSET));

$action = $this->handle(ContextMenuHandler::NAME, [
'source' => (string) $source,
'offset' => self::ORIGINAL_OFFSET,
'current_path' => $source->path(),
]);

$this->assertInstanceOf(InputCallbackResponse::class, $action);
$this->assertEquals(self::ORIGINAL_OFFSET, $action->callbackAction()->parameters()['offset']);
}

public function testReplaceTokens()
{
$this->container->get(ContextMenuExtension::SERVICE_REQUEST_HANDLER)->willReturn(
Expand All @@ -135,7 +167,7 @@ public function testReplaceTokens()
$this->classFileNormalizer->classToFile('string')->willReturn(__FILE__);

$source = SourceCode::fromPathAndString('/hello.php', self::SOURCE);
$offset = ByteOffset::fromInt(8);
$offset = ByteOffset::fromInt(self::ORIGINAL_OFFSET);

$this->offsetFinder->find($source, $offset)
->willReturn($offset);
Expand Down