diff --git a/src/Commands/Visit.php b/src/Commands/Visit.php index 4d26e89..3c8f46c 100644 --- a/src/Commands/Visit.php +++ b/src/Commands/Visit.php @@ -59,6 +59,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('No active ticket, please use tl visit {ticket_id} to specifiy a ticket.'); 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); } @@ -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; } diff --git a/tests/Commands/AddTest.php b/tests/Commands/AddTest.php index 4027155..89d28af 100644 --- a/tests/Commands/AddTest.php +++ b/tests/Commands/AddTest.php @@ -4,7 +4,6 @@ use Larowlan\Tl\Slot; use Larowlan\Tl\Tests\TlTestBase; -use Larowlan\Tl\Ticket; /** * The test for tl add command. diff --git a/tests/Commands/VisitTest.php b/tests/Commands/VisitTest.php new file mode 100644 index 0000000..b3ff27d --- /dev/null +++ b/tests/Commands/VisitTest.php @@ -0,0 +1,98 @@ +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', + ]); + } + +}