Skip to content

Commit

Permalink
Merge pull request #122 from larowlan/120-visit-alias
Browse files Browse the repository at this point in the history
[#120] Support aliases in tl visit.
  • Loading branch information
jibran committed Sep 20, 2019
2 parents d1cc2e2 + d1e54e5 commit 4c89932
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Commands/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('<error>No active ticket, please use tl visit {ticket_id} to specifiy a ticket.</error>');
return;
}
if ($alias = $this->repository->loadAlias($issue_number)) {
$issue_number = $alias;
}
$url = $this->connector->ticketUrl($issue_number, isset($data) ? $data->getConnectorId() : $this->getConnector($input, $output, $issue_number));
$this->open($url, $output);
}
Expand All @@ -84,7 +87,7 @@ protected function open($url, OutputInterface $output) {
$browser = 'start';
}

if ($browser) {
if ($browser && !isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
shell_exec($browser . ' ' . escapeshellarg($url));
return;
}
Expand Down
1 change: 0 additions & 1 deletion tests/Commands/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Larowlan\Tl\Slot;
use Larowlan\Tl\Tests\TlTestBase;
use Larowlan\Tl\Ticket;

/**
* The test for tl add command.
Expand Down
98 changes: 98 additions & 0 deletions tests/Commands/VisitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace Larowlan\Tl\Tests\Commands;

use Larowlan\Tl\Tests\TlTestBase;

/**
* The test for tl visit command.
*
* @coversDefaultClass \Larowlan\Tl\Commands\Visit
* @group Commands
*/
class VisitTest extends TlTestBase {

/**
* Tests visit command with minimum params.
*
* @covers ::execute
*/
public function testNoActiveVisit() {
$output = $this->executeCommand('visit');
$this->assertContains('No active ticket, please use tl visit {ticket_id} to specifiy a ticket.', $output->getDisplay());
}

/**
* Tests visit command with active ticket.
*
* @covers ::execute
*/
public function testActiveVisit() {
$this->setupConnector();
$this->getMockConnector()->expects($this->once())
->method('ticketUrl')
->with(1234, 'connector.redmine')
->willReturn('https://www.jetbrains.com');
$this->executeCommand('start', [
'issue_number' => '1234',
]);
$this->assertTicketIsOpen(1234);
$output = $this->executeCommand('visit');
$this->assertContains('Could not find a browser helper.', $output->getDisplay());
}

/**
* Tests visit command with issue param.
*
* @covers ::execute
*/
public function testIssueVisit() {
$this->setupConnector();
$this->getMockConnector()->expects($this->once())
->method('ticketUrl')
->with(1234, 'connector.redmine')
->willReturn('https://www.jetbrains.com');
$output = $this->executeCommand('visit', [
'issue' => '1234',
]);
$this->assertContains('Could not find a browser helper.', $output->getDisplay());
}

/**
* Tests visit command with issue alias param.
*
* @covers ::execute
*/
public function testAliasVisit() {
$this->setupConnector();
$this->getMockConnector()->expects($this->once())
->method('ticketUrl')
->with(1234, 'connector.redmine')
->willReturn('https://www.jetbrains.com');
$output = $this->executeCommand('alias', [
'ticket_id' => 1234,
'alias' => 'pony',
]);
$this->assertRegExp('/Created new alias/', $output->getDisplay());
$output = $this->executeCommand('visit', [
'issue' => 'pony',
]);
$this->assertContains('Could not find a browser helper.', $output->getDisplay());
}

/**
* Tests visit command with invalid issue.
*
* @covers ::execute
*/
public function testInvalidTicketVisit() {
$this->getMockConnector()->expects($this->once())
->method('spotConnector')
->willReturn(FALSE);
$this->expectException(\InvalidArgumentException::class);
$this->executeCommand('visit', [
'issue' => '5678',
]);
}

}

0 comments on commit 4c89932

Please sign in to comment.