Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger: detect default source context #853

Merged
merged 3 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
35 changes: 20 additions & 15 deletions src/Debugger/Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,30 @@ public function __construct($sourceRoot, array $options = [])
? $options['client']
: new DebuggerClient();

$this->sourceRoot = realpath($sourceRoot);
$options += [
'sourceContext' => [],
'extSourceContext' => [],
'uniquifier' => null,
'description' => null
];

$extSourceContext = array_key_exists('extSourceContext', $options)
? [$options['extSourceContext']]
: $this->defaultExtSourceContext();
$this->sourceRoot = realpath($sourceRoot);

$uniquifier = array_key_exists('uniquifier', $options)
? $options['uniquifier']
: $this->defaultUniquifier();
$sourceContext = $options['sourceContext'] ?: $this->defaultSourceContext();
$extSourceContext = $options['extSourceContext'];
if (!$extSourceContext && $sourceContext) {
$extSourceContext = [
'context' => $sourceContext
];
}

$description = array_key_exists('description', $options)
? $options['description']
: $this->defaultDescription();
$uniquifier = $options['uniquifier'] ?: $this->defaultUniquifier();
$description = $options['description'] ?: $this->defaultDescription();

$this->debuggee = $client->debuggee(null, [
'uniquifier' => $uniquifier,
'description' => $description,
'extSourceContexts' => $extSourceContext
'extSourceContexts' => $extSourceContext ? [$extSourceContext] : []
]);

$this->debuggee->register();
Expand Down Expand Up @@ -179,13 +185,12 @@ private function defaultDescription()
return gethostname() . ' - ' . getcwd();
}

private function defaultExtSourceContext()
private function defaultSourceContext()
{
$sourceContextFile = $this->sourceRoot . '/source-contexts.json';
$sourceContextFile = implode(DIRECTORY_SEPARATOR, [$this->sourceRoot, 'source-context.json']);
if (file_exists($sourceContextFile)) {
return json_decode(file_get_contents($sourceContextFile), true);
} else {
return [];
}
return [];
}
}
23 changes: 22 additions & 1 deletion tests/unit/Debugger/DaemonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testSpecifyExtSourceContext()
]);
}

public function testDefaultSourceContext()
public function testEmptyDefaultSourceContext()
{
$this->debuggee->register(Argument::any())->shouldBeCalled();
$this->client->debuggee(null, Argument::withEntry('extSourceContexts', []))
Expand All @@ -114,6 +114,27 @@ public function testDefaultSourceContext()
]);
}

public function testDefaultSourceContext()
{
$expectedSourceContext = [
'context' => [
'git' => [
'revisionId' => '81b20d097da02ebb6c6fdfbf6900c67a90f2c54b',
'url' => 'https://github.com/GoogleCloudPlatform/google-cloud-php.git'
]
]
];
$this->debuggee->register(Argument::any())->shouldBeCalled();
$this->client->debuggee(null, Argument::withEntry('extSourceContexts', [$expectedSourceContext]))
->willReturn($this->debuggee->reveal())->shouldBeCalled();

$root = implode(DIRECTORY_SEPARATOR, [__DIR__, 'example']);

This comment was marked as spam.

This comment was marked as spam.

$daemon = new Daemon($root, [
'client' => $this->client->reveal(),
'storage' => $this->storage->reveal()
]);
}

public function testFetchesBreakpoints()
{
$resp = [
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Debugger/example/source-context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"git": {
"revisionId": "81b20d097da02ebb6c6fdfbf6900c67a90f2c54b",
"url": "https://github.com/GoogleCloudPlatform/google-cloud-php.git"
}
}