Skip to content

Commit

Permalink
Debugger: Expose setBreakpoint method (#870)
Browse files Browse the repository at this point in the history
* Add setBreakpoint function to Debuggee

* Add ability to pass request options to the debugger endpoints

* Fix tests
  • Loading branch information
chingor13 authored and dwsupplee committed Jan 26, 2018
1 parent e620fd0 commit c59f336
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/Debugger/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public function listBreakpoints(array $args = []);
* @param array $args
*/
public function updateBreakpoint(array $args);

/**
* Sets a breakpoint.
*
* @param array $args
*/
public function setBreakpoint(array $args);
}
10 changes: 10 additions & 0 deletions src/Debugger/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ public function updateBreakpoint(array $args)
{
return $this->send('controller.resources.debuggees.resources.breakpoints', 'update', $args);
}

/**
* Sets a breakpoint.
*
* @param array $args
*/
public function setBreakpoint(array $args)
{
return $this->send('debugger.resources.debuggees.resources.breakpoints', 'set', $args);
}
}
46 changes: 42 additions & 4 deletions src/Debugger/Debuggee.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,51 @@ public function breakpointsWithWaitToken(array $options = [])
* @codingStandardsIgnoreEnd
*
* @param Breakpoint $breakpoint The modified breakpoint.
* @param array $options [optional] Configuration options. See
* {@see Google\Cloud\Core\RequestWrapper::__construct()} for
* configuration options which apply to all network requests.
* @return void
* @throws ServiceException
*/
public function updateBreakpoint(Breakpoint $breakpoint)
public function updateBreakpoint(Breakpoint $breakpoint, array $options = [])
{
$this->connection->updateBreakpoint([
'debuggeeId' => $this->id,
'id' => $breakpoint->id(),
'breakpoint' => $breakpoint
]);
] + $options);
}

/**
* Set a breakpoint for this debuggee.
*
* Example:
* ```
* $breakpoint = $debuggee->setBreakpoint('DebuggerClient.php', 10);
* ```
*
* @codingStandardsIgnoreStart
* @see https://cloud.google.com/debugger/api/reference/rest/v2/debugger.debuggees.breakpoints/set Breakpoint set API documentation.
* @codingStandardsIgnoreEnd
*
* @param string $path Path to the source file.
* @param int $line Line within the source file.
* @param array $options [optional] Array of Breakpoint constructor arguments. See
* {@see Google\Cloud\Debugger\Breakpoint::__construct()} for
* configuration details. See
* {@see Google\Cloud\Core\RequestWrapper::__construct()} for
* configuration options which apply to all network requests.
*/
public function setBreakpoint($path, $line, array $options = [])
{
$resp = $this->connection->setBreakpoint([
'debuggeeId' => $this->id,
'location' => [
'path' => $path,
'line' => $line
]
] + $options);
return new Breakpoint($resp['breakpoint']);
}

/**
Expand All @@ -305,13 +340,16 @@ public function updateBreakpoint(Breakpoint $breakpoint)
* @codingStandardsIgnoreEnd
*
* @param Breakpoint[] $breakpoints The modified breakpoints.
* @param array $options [optional] Configuration options. See
* {@see Google\Cloud\Core\RequestWrapper::__construct()} for
* configuration options which apply to all network requests.
* @return void
* @throws ServiceException
*/
public function updateBreakpointBatch(array $breakpoints)
public function updateBreakpointBatch(array $breakpoints, array $options = [])
{
foreach ($breakpoints as $breakpoint) {
$this->updateBreakpoint($breakpoint);
$this->updateBreakpoint($breakpoint, $options);
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/snippets/Debugger/DebuggeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,15 @@ public function testUpdateBreakpointBatch()
$snippet->addLocal('breakpoint2', $breakpoint2);
$snippet->invoke('debuggee');
}

public function testSetBreakpoint()
{
$this->connection->setBreakpoint(Argument::any())->willReturn(['breakpoint' => ['id' => 'breakpoint1']])->shouldBeCalled();
$debuggee = new Debuggee($this->connection->reveal(), ['project' => 'project']);
$snippet = $this->snippetFromMethod(Debuggee::class, 'setBreakpoint');
$snippet->addLocal('debuggee', $debuggee);
$resp = $snippet->invoke('breakpoint');
$breakpoint = $resp->returnVal();
$this->assertInstanceOf(Breakpoint::class, $breakpoint);
}
}
13 changes: 3 additions & 10 deletions tests/system/Debugger/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,9 @@ public function testRegisterSetUseBreakpoint($transport)
$this->assertNotEmpty($debuggee->id());

// Set a breakpoint
$client = new GapicClient();
$breakpoint = new GapicBreakpoint();
$location = new SourceLocation();
$location->setPath('tests/system/Debugger/BasicTest.php');
$location->setLine(__LINE__);
$breakpoint->setLocation($location);
$resp = $client->setBreakpoint($debuggee->id(), $breakpoint, 'google.com/php/v0.1');
$bp = $resp->getBreakpoint();
$this->assertNotEmpty($bp->getId());
$breakpoint = $debuggee->setBreakpoint('tests/system/Debugger/BasicTest.php', __LINE__);
$this->assertInstanceOf(Breakpoint::class, $breakpoint);
$this->assertNotNull($breakpoint->location());

// Fetch the list of breakpoints
$breakpoints = $debuggee->breakpoints();
Expand All @@ -91,7 +85,6 @@ public function testRegisterSetUseBreakpoint($transport)
);

// fulfill a breakpoint
$breakpoint = $breakpoints[0];
$this->assertTrue($breakpoint->resolveLocation());
$breakpoint->finalize();
$debuggee->updateBreakpoint($breakpoint);
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Debugger/Connection/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function methodProvider()
['listDebuggees'],
['registerDebuggee'],
['listBreakpoints'],
['updateBreakpoint']
['updateBreakpoint'],
['setBreakpoint']
];
}
}
14 changes: 14 additions & 0 deletions tests/unit/Debugger/DebuggeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ public function testUpdatesBreakpoint()
$debuggee->updateBreakpoint($breakpoint);
}

public function testSetsBreakpoint()
{
$this->connection->setBreakpoint(Argument::that(function ($args) {
return $args['debuggeeId'] == 'debuggee1' &&
$args['location']['path'] == '/path/to/file.php' &&
$args['location']['line'] == 10;
}))->willReturn(['breakpoint' => ['id' => 'breakpoint1']]);
$debuggee = new Debuggee($this->connection->reveal(), ['id' => 'debuggee1', 'project' => 'project1']);

$breakpoint = $debuggee->setBreakpoint('/path/to/file.php', 10);
$this->assertInstanceOf(Breakpoint::class, $breakpoint);
$this->assertEquals('breakpoint1', $breakpoint->id());
}

// Debug agents should populate both sourceContexts and extSourceContexts.
public function testProvidesDeprecatedSourceContext()
{
Expand Down

0 comments on commit c59f336

Please sign in to comment.