Skip to content

Commit

Permalink
fix: Prevent setting null debuggee ID (#2252)
Browse files Browse the repository at this point in the history
* fix: Prevent setting null debuggee ID

* add test coverage, reorder constructor property settings
  • Loading branch information
jdpedrie authored Aug 16, 2019
1 parent 23c1c8d commit d345456
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
19 changes: 12 additions & 7 deletions Debugger/src/Debuggee.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ public function __construct(ConnectionInterface $connection, array $info = [])
'extSourceContexts' => [],
'uniquifier' => null,
'description' => null,
'labels' => []
'labels' => [],
'project' => null
];

$this->id = $info['id'];
$this->project = $info['project'];
$this->uniquifier = $info['uniquifier'];
$this->description = $info['description'];
$this->status = $info['status'];
$this->agentVersion = $info['agentVersion'];
$this->isInactive = $info['isInactive'];
$this->agentVersion = $info['agentVersion'];
$this->status = $info['status'];
$this->extSourceContexts = $info['extSourceContexts'];
$this->uniquifier = $info['uniquifier'];
$this->description = $info['description'];
$this->labels = $info['labels'];
$this->project = $info['project'];
}

/**
Expand Down Expand Up @@ -367,7 +368,6 @@ public function updateBreakpointBatch(array $breakpoints, array $options = [])
public function info()
{
$info = [
'id' => $this->id,
'project' => $this->project,
'uniquifier' => $this->uniquifier,
'description' => $this->description,
Expand All @@ -384,6 +384,11 @@ public function info()
}, $this->extSourceContexts)
];

// Do not include the ID unless it is set.
if ($this->id) {
$info['id'] = $this->id;
}

if ($this->status instanceof StatusMessage) {
$info['status'] = $this->status->info();
} elseif ($this->status) {
Expand Down
13 changes: 12 additions & 1 deletion Debugger/tests/Unit/DebuggeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testProvidesDeprecatedSourceContext()
public function testRegisterSetsDebuggeeId()
{
$this->connection->registerDebuggee(Argument::that(function ($args) {
return $args['debuggee']['id'] == null;
return !isset($args['debuggee']['id']);
}), Argument::any())->willReturn([
'debuggee' => [
'id' => 'debuggee1'
Expand Down Expand Up @@ -167,4 +167,15 @@ public function testDebuggeeExtendedSourceContextSerialization()
$this->assertArrayHasKey('sourceContexts', $info);
$this->assertCount(1, $info['sourceContexts']);
}

public function testDebuggeeOmitsId()
{
$debuggee = new Debuggee($this->connection->reveal(), []);
$this->assertArrayNotHasKey('id', $debuggee->info());

$debuggee = new Debuggee($this->connection->reveal(), [
'id' => 'foo'
]);
$this->assertArrayHasKey('id', $debuggee->info());
}
}

0 comments on commit d345456

Please sign in to comment.