Skip to content

Commit

Permalink
Adds debugger system test (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored Jan 19, 2018
1 parent 243813a commit 595f870
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Debugger/DebuggerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function debuggee($id = null, array $options = [])
*/
public function debuggees(array $extras = [])
{
$res = $this->connection->listDebuggees(['projectId' => $this->projectId] + $extras);
$res = $this->connection->listDebuggees(['project' => $this->projectId] + $extras);
if (is_array($res) && array_key_exists('debuggees', $res)) {
return array_map(function ($info) {
return new Debuggee($this->connection, $info);
Expand Down
114 changes: 114 additions & 0 deletions tests/system/Debugger/BasicTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Tests\System\Debugger;

use Google\Cloud\Debugger\Breakpoint;
use Google\Cloud\Debugger\Debuggee;
use Google\Cloud\Debugger\DebuggerClient;
use Google\Cloud\Debugger\V2\Gapic\Debugger2GapicClient as GapicClient;
use Google\Cloud\Debugger\V2\Breakpoint as GapicBreakpoint;
use Google\Cloud\Debugger\V2\SourceLocation;

use PHPUnit\Framework\TestCase;

/**
* @group debugger
*/
class BasicTest extends TestCase
{
private $debuggerClient;

public function setUp()
{
$this->debuggerClient = new DebuggerClient([
'keyFilePath' => getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH')
]);
}

/**
* @dataProvider transports
*/
public function testCanListDebuggees($transport)
{
$debuggerClient = $this->getClient($transport);

$debuggees = $debuggerClient->debuggees();
$this->assertInternalType('array', $debuggees);
$this->assertContainsOnlyInstancesOf(
Debuggee::class,
$debuggees
);
}

/**
* @dataProvider transports
*/
public function testRegisterSetUseBreakpoint($transport)
{
$debuggerClient = $this->getClient($transport);

$debuggee = $debuggerClient->debuggee('', [
'uniquifier' => 'debugger-system-test',
'description' => 'Debugger System Test'
]);

// Register the debuggee
$debuggee->register();
$this->assertNotEmpty($debuggee->id());

// Set a breakpoint
$client = new GapicClient();
$breakpoint = new GapicBreakpoint();
$location = new SourceLocation();
$location->setPath('web/app.php');
$location->setLine(10);
$breakpoint->setLocation($location);
$resp = $client->setBreakpoint($debuggee->id(), $breakpoint, 'google.com/php/v0.1');
$bp = $resp->getBreakpoint();
$this->assertNotEmpty($bp->getId());

// Fetch the list of breakpoints
$breakpoints = $debuggee->breakpoints();
$this->assertInternalType('array', $breakpoints);
$this->assertContainsOnlyInstancesOf(
Breakpoint::class,
$breakpoints
);

// fulfill a breakpoint
$breakpoint = $breakpoints[0];
$breakpoint->finalize();
$debuggee->updateBreakpoint($breakpoint);
}

public function getClient($transport)
{
return new DebuggerClient([
'transport' => $transport,
'keyFilePath' => getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH')
]);
}

public function transports()
{
return [
['grpc'],
['rest']
];
}
}
4 changes: 2 additions & 2 deletions tests/unit/Debugger/DebuggerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setUp()

public function testListsDebuggees()
{
$this->connection->listDebuggees(['projectId' => 'project1'])->willReturn([
$this->connection->listDebuggees(['project' => 'project1'])->willReturn([
'debuggees' => [
['id' => 'debuggee1', 'project' => 'project1'],
['id' => 'debuggee2', 'project' => 'project1'],
Expand All @@ -54,7 +54,7 @@ public function testListsDebuggees()

public function testListsDebuggeesEmpty()
{
$this->connection->listDebuggees(['projectId' => 'project1'])->willReturn([]);
$this->connection->listDebuggees(['project' => 'project1'])->willReturn([]);
$this->client->setConnection($this->connection->reveal());
$debuggees = $this->client->debuggees();
$this->assertCount(0, $debuggees);
Expand Down

0 comments on commit 595f870

Please sign in to comment.