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

[#120] Support aliases in tl visit. #122

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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'])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of ugly. Do we have a better way to do this?

Copy link
Owner

@larowlan larowlan Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could put a constant in phpunit.xml and then use !defined()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's almost the same thing :D. I tested it locally it works. We can improve it later.

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',
]);
}

}